Archive for May, 2009

PHP short-hand IF/Else statement

Share/Save

Let’s keep it simple:

Regular way:

if (statement) {
  $variable = "return this if true";
}
else {
  $variable = "return this if false";
}

Short way:

$variable = (statement) ? "return if true" : "return if false";

And this is how it works: statement ? if-true : if-false