Skip to content

Instantly share code, notes, and snippets.

@p0358
Created January 4, 2018 02:17
Show Gist options
  • Save p0358/00f58b7361ce993905f7047941122ed3 to your computer and use it in GitHub Desktop.
Save p0358/00f58b7361ce993905f7047941122ed3 to your computer and use it in GitHub Desktop.
PHP any bool case in any switch
<?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