Link to home
Start Free TrialLog in
Avatar of walker6o9
walker6o9

asked on

Php If statement

What do : and ? mean in if statements?

As in
if($redirect = ($mobile_browser==true) ? $mobileredirect : $desktopredirect){
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of markh789
markh789

It means:
if (STATEMENT) ? STATEMENT_IS_TRUE :  STATEMENT_IS_FALSE)

So it could be

$var = ($hello == world) ? "yes" : "no");

if ($var == "yes") {
 echo "Yay! We got a Yes!";
} else {
 echo "Aw.. We go a No.";
}

It's just a quicker way to write:
$var = ($hello == world) ? "yes" : "no");

Then to write:
if ($hello == world) {
 $var = "yes";
} else {
 $var = "no";
}
it's called the ternary operator


http://uk.php.net/ternary
It's so known for its three parts: (1) statement, (2) true action and (3) false action.

http://dictionary.reference.com/browse/ternary