【问题标题】:array switch case statement数组 switch case 语句
【发布时间】:2011-08-15 19:29:05
【问题描述】:

我有一个带有像这样的子数组的数组

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:
}

我该怎么做。 谢谢

【问题讨论】:

    标签: php cakephp-1.3


    【解决方案1】:

    由于 $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 ;
         }
     }
    

    【讨论】: