我有一个数组,其中包含这样的子数组
Array
(
[0] => Array
(
[customers] => Array
(
[id] =>
)
[Products] => Array
(
[id] =>
)
[Models] => Array
(
[id] => 151
[SubModels] => Array
(
[ol] =>
)
[Noice] =>
)
)
我想在数组上做一个switch语句
像这样
switch($array){
case Products:
case customers:
case Models:
}
我该怎么做。 谢谢
最佳答案
因为 $array 在其中包含一个数组,看起来您实际上想要查看索引为 $array[0] 的数组的键
foreach ($array[0] as $key => $value) {
switch ($key) {
case 'Products' :
// do something
break ;
case 'customers' :
// do something
break ;
case 'Models' :
// do something
break ;
}
}
关于php - 数组 switch case 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5837674/