Welcome Guest, Not a member yet? Register   Sign In
What is this PHP syntax called? ($var) ? $var = $var2 : $var = FALSE;
#1

[eluser]Fenix[/eluser]
Can somebody point me to documentation for this PHP syntax or tell me what it is called?

Code:
($var) ? $var = $var2 : $var = FALSE;
#2

[eluser]Shadab[/eluser]
That's a shortcut syntax to the If...Then...Else.
Quote:(Condition) ? (Do this if it evaluates to TRUE) : (Do this if it evaluates to FALSE) ;

They are equivalent :
Code:
if ($var === TRUE) {
   $xyz = 'foo';
}else {
   $xyz = 'bar';
}

Code:
$xyz = ($var === TRUE) ? 'foo' : 'bar' ;
#3

[eluser]kgill[/eluser]
It's called: ternary operator
#4

[eluser]jedd[/eluser]
Or, to answer the question:

[url="http://us3.php.net/language.operators.comparison#language.operators.comparison.ternary"]http://us3.php.net/language.operators.comparison#language.operators.comparison.ternary[/url]




Theme © iAndrew 2016 - Forum software by © MyBB