Created
January 4, 2018 02:17
-
-
Save p0358/00f58b7361ce993905f7047941122ed3 to your computer and use it in GitHub Desktop.
PHP any bool case in any switch
This file contains hidden or 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
<?php | |
// PHP any bool case in any switch | |
// useful if you want to do also some other switch case | |
// being exceptional result of some separate check/comparsion | |
//$t = 'text!'; | |
$t = ''; | |
$b = true; // any bool check you want in the switch, it can be inlined in the case statement too | |
switch ($t) { | |
case (boolval($t) ? true === $b : true !== $b): | |
//case $b: | |
echo 'it works!'; | |
case 'text!': | |
echo $t; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment