php - 数组 switch case 语句

标签 php cakephp-1.3

我有一个数组,其中包含这样的子数组

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/

相关文章:

php - Mime/Base 64 编码

php - 在 Emacs 中设置 PHP 的初始缩进级别?

php - cakePHP 中的动态页面

CakePHP 在路由中使用正则表达式变量捕获?

php - 在php中将时间戳转换为日期

php - 获取父工单的用户 ID - MySQL

php - 四舍五入到最近的 5 分钟 php mysqli

php - 下载cakephp手册

cakephp - 在CakePHP中为一个模型保存多个记录

php - 为每个数组运行插入重复更新