Is it possible to generate the cases for a switch in php using an array? Something like:
$x=array(
0 => 'foo',
1 => 'bar',
2 => 'foobar'
);
$y='foobar'
switch($y) {
foreach($x as $i) {
case $i:
print 'Variable $y tripped switch: '.$i.'<br>';
break;
}
}
I would like to be able to pull the case values from a database and loop through them with a while() loop.
switchis overcomplicating it. What you want is not possible, and for good reason - that code could be written as simplyforeach($x as $i) { if ($i == $y) { print 'Variable $y tripped switch: '.$i.'<br>'; } }(assuming you got your$xs and your$is confused in that code sample)