Skip to content

Instantly share code, notes, and snippets.

@AWOL-TECH
Created September 8, 2023 11:40
Show Gist options
  • Save AWOL-TECH/9fb755b00f3205ef36e0f19e0f760eaa to your computer and use it in GitHub Desktop.
Save AWOL-TECH/9fb755b00f3205ef36e0f19e0f760eaa to your computer and use it in GitHub Desktop.
Created as a funny response to a programmer joke meme about using switch case instead of ifelse... however this code turns out to work and could be useful in some weird usecase so here it is.
<?php
$switch_case = 'something'; // define anything as your variable, doesn't have to be a string can be any type
if (isset($switch_case)) {
switch ($switch_case) {
case 'true':
echo "switch_case is true";
break;
case 'false':
echo "switch_case is false";
break;
default:
if (is_int($switch_case)) {
echo "switch_case is an integer";
} elseif (is_string($switch_case)) {
echo "switch_case is a string";
} elseif (is_bool($switch_case)) {
echo "switch_case is a boolean value";
} elseif (is_object($switch_case)) {
echo "switch_case is an object";
} elseif (is_array($switch_case)) {
echo "switch_case is an array";
} elseif ($switch_case != null) {
echo "switch_case is defined but unknown";
} else {
echo "nothing matched";
}
break;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment