pb&j
02-13-2003, 12:32 PM
Originally posted by Ökii
tertiary (short if/else) operator
( a = b ) ? [do if true] : [do if false] ;
echo (7 > 4) ? 'true' : 'false'; => true
echo (7 < 4) ? 'true' : 'false'; => false
the first clause after the ? is assigned if the parenthesised expression equates to true, else the second clause is.
only works for single method clauses tho.
Tertiary is cool. So are additional elseif represented by further question marks?
( a = b ) ? [do if true] ? [do if first false but this true] : [do if false];
tertiary (short if/else) operator
( a = b ) ? [do if true] : [do if false] ;
echo (7 > 4) ? 'true' : 'false'; => true
echo (7 < 4) ? 'true' : 'false'; => false
the first clause after the ? is assigned if the parenthesised expression equates to true, else the second clause is.
only works for single method clauses tho.
Tertiary is cool. So are additional elseif represented by further question marks?
( a = b ) ? [do if true] ? [do if first false but this true] : [do if false];