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";

  echo $var;

If $condition is true, this will output "foo", otherwise, it'll output "false".

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, like this:

  ($condition && $other_condition) && $var = "foo";

Enjoy!

--Dave

_______________________________________________

UPHPU mailing list
[email protected]
http://uphpu.org/mailman/listinfo/uphpu
IRC: #uphpu on irc.freenode.net

Reply via email to