2011-04-29 42 views
5

我与子阵列来在这样阵列开关case语句

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

我将如何做到这一点。 感谢

回答

11

因为$数组保存在它的阵列,它看起来像你真的想看看阵列中的$阵列索引键[0]

foreach ($array[0] as $key => $value) { 
    switch ($key) { 
     case 'Products' : 
      // do something 
      break ; 
     case 'customers' : 
      // do something 
      break ; 
     case 'Models' : 
      // do something 
      break ; 
    } 
}