[UPHPU] short syntax without the else?
dave at thesmithfam.org
Sat Jan 19 21:31:34 MST 2008
Wade Preston Shearer wrote:
> …without the that? Like this…
> $var = condition ? this;
Nope. It's called the ternary operator, because there are 3 parts to it.
The ':' and the operand after it are required.
You can, however, use the short-circuited && operator like this:
$condition && $var = "this";
Here's an example:
$condition = false;
$var = "bar";
// Here's the magic
$condition && $var = "foo";
If $condition is true, this will output "foo", otherwise, it'll output
This is called short-circuited because the interpreter is smart enough
to not evaluate the second half of an && if the first half is false.
Be sure to use parentheses when your condition has multiple conditions,
($condition && $other_condition) && $var = "foo";
More information about the UPHPU