tags:

views:

81

answers:

5

Possible Duplicate:
What is the PHP ? : operator called and what does it do?

I feed like a goof but I don't entirely understand what's happening in this code:

$var .= ($one || $two) ? function_one( $one, $another) : function_two( $two, $another);

Does that say if $one or $two then $var is equal to fuction_one(), else function_two()? What's the purpose of using this syntax -- speed?

+1  A: 

function_one() and function_two() both return a value.

You are concatenating $var to the return value of one of these function based on an if statement that evaluates $one or $two, If $one or $tow are assigned or return true the returned from function_one() is concatenated otherwise the value returned from function_tow() is.

Babiker
+3  A: 

$var would append to itself the value from the return of function_one() if $one or $two evaluates to true, and would append the result of function_two() otherwise.

Alexandru Luchian
+1  A: 

$var .= ($one || $two) ? function_one( $one, $another) : function_two( $two, $another);

append $var with output of function_one() or function_two()

if $one is true then execute function_one() else execute function_two()

Foobar
A: 

looks like thats what it does. as for the reason to use it, laziness?

dude
+3  A: 

If either $one is true, or $two is true, then the result of calling function_one is appended to $var. Otherwise, the result of calling function_two is appended to $var.

It's basically shorthand for:

if ($one || $two) {
  $var .= function_one( $one, $another);
} else {
  $var .= function_two( $two, $another);
}
Richard Fearn