What is IF-ELSE ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hilal6
Forum Newbie
Posts: 6
Joined: Fri Jun 26, 2015 1:15 pm

What is IF-ELSE ?

Post 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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: What is IF-ELSE ?

Post 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
Post Reply