gpt4 book ai didi

php - 从数组在 php 中生成开关案例?

转载 作者:可可西里 更新时间:2023-11-01 13:43:14 26 4
gpt4 key购买 nike

是否可以使用数组为 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com