note 50927 deleted from control-structures.switch by cmb

From: Date: Sun, 21 Apr 2019 11:47:34 +0000
Subject: note 50927 deleted from control-structures.switch by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-210637@lists.php.net to get a copy of this message
Note Submitter: ach aat bitfabrik doot de ---- So instead of writing the code shown below it would have to be like this: <?php $x = 18; $y = 6; switch ($x) { case ((($y * 4) || (9 * 3))?$x:false): echo "Member"; break; default: echo "Not a member"; } ?> So now the case expression contains an if statement in simplified notation which either returns the value of $x if the expression is true (so the case matches) or false, if the expression was false (so the case does not match). Be aware that it only works if $x never actually is "false" because then it would match in either case. So the "false" in the above code should always be any random value which is not a possible value for $x.

« previous php.notes (#210637) next »