I don't see comparison and boolean operators in case clauses of the switch statement documented in the php documentation (i.e.
www.php.net/manual).
The code below seems to work as one would expect. But is it valid and supported php code?
I'm using on Mac OS 10.6:
PHP 5.3.8 (cli) (built: Dec 5 2011 21:24:09)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
I want to be sure this syntax will be supported in future versions of php.
Thanks for your help.
Andynic
<?php
$a = "3abc";
switch ($a)
{
case ($a == "1" || $a == "2"):
echo "a is 1 or 2<br />";
break;
case (stripos($a, '3') !== false ):
echo "a is 3 or 4<br />";
break;
case "5":
echo "a is 5<br />";
break;
case "6":
echo "a is 6<br />";
break;
default:
echo "dflt<br />";
}
?>