walker6o9
asked on
Php If statement
What do : and ? mean in if statements?
As in
if($redirect = ($mobile_browser==true) ? $mobileredirect : $desktopredirect){
As in
if($redirect = ($mobile_browser==true) ? $mobileredirect : $desktopredirect){
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It's so known for its three parts: (1) statement, (2) true action and (3) false action.
http://dictionary.reference.com/browse/ternary
http://dictionary.reference.com/browse/ternary
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";
}