Page 1 of 1

What is IF-ELSE ?

Posted: Thu Aug 06, 2015 4:34 am
by hilal6
Giving Zend exam soon and i came across IF-ELSE in the control structures heading.

I know about if and else and even elseif but what the hell is IF-ELSE?

The guide book says its a ternary operator

Re: What is IF-ELSE ?

Posted: Thu Aug 06, 2015 6:27 am
by Celauran
The ternary operator in PHP is ?, which is a sort of shorthand for if/else

Code: Select all

if ($x == 1) {
    $y = 1;
} else {
    $y = 2;
}

Code: Select all

$y = ($x == 1) ? 1 : 2;
Are equivalent statements