Skip to content

Instantly share code, notes, and snippets.

@LGitHub-sprout
Created November 16, 2020 20:04
Show Gist options
  • Save LGitHub-sprout/8964b2b52f148ec189e85248babaf536 to your computer and use it in GitHub Desktop.
Save LGitHub-sprout/8964b2b52f148ec189e85248babaf536 to your computer and use it in GitHub Desktop.
Non-looping conditionals: switch
/**
* 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