是否可以使用数组为 php 中的开关生成 case?像这样的东西:
$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;
}
}
我希望能够从数据库中提取案例值并使用 while() 循环遍历它们。
最佳答案
我相信您正在寻找的是与此类似的东西
foreach ($x as $i) {
switch($i){
case $y:
print 'Variable $x tripped switch: '.$i.'<br>';
break;
}
}
关于php - 从数组在 php 中生成开关案例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13923512/