Created
November 16, 2020 20:04
-
-
Save LGitHub-sprout/8964b2b52f148ec189e85248babaf536 to your computer and use it in GitHub Desktop.
Non-looping conditionals: switch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Control structures: switch | |
* | |
* O'Reilly book: useful when on $var or result of expression can have multiple values. | |
* | |
* intersting examples in user notes | |
* https://www.php.net/manual/en/control-structures.switch.php | |
*/ | |
// $foo = "is not set"; | |
// $foo = "peep"; | |
$foo = "poop"; | |
switch ( $foo ) | |
{ | |
case "poop": | |
echo "You've selected poop."; | |
break; | |
case "pee": | |
echo "You've selected pee."; | |
break; | |
default: echo "Default switch, stitch!"; | |
break; | |
} | |
if ( $foo === "poop" || $foo == "pee" ) { | |
echo "<p>$foo, baby!!</p>"; | |
} | |
echo "<p>More pooping yet to poop ... </p>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment