在PHP中转换2d数组中的3d数组

时间:2014-07-21 09:27:50

标签: php arrays

我有一个从函数返回的数组,它就像 这用于打印网格,但网格变为空白,甚至没有单个条目

Array
(
   [0] => Array
    (
        [0] => Array
            (
                [product_id] => 47
                [name] => Test Product 1
                [description] => tesw
                [sku] => test050
                [price] => 125
                [quantity] => 12
                [status] => 1
                [created_at] => 2014-07-09 12:53:07
                [updated_at] => 0000-00-00 00:00:00
            )

        [1] => Array
            (
                [product_id] => 49
                [name] => Test Product 3
                [description] => 
                [sku] => test053
                [price] => 3600
                [quantity] => 56
                [status] => 2
                [created_at] => 2014-07-09 12:53:07
                [updated_at] => 0000-00-00 00:00:00
            )

        [2] => Array
            (
                [product_id] => 50
                [name] => Test Product 4
                [description] => test
                [sku] => test054
                [price] => 5450
                [quantity] => 5
                [status] => 1
                [created_at] => 2014-07-09 12:53:07
                [updated_at] => 0000-00-00 00:00:00
            )
         )
       )

并存储在$ n中,如果我这样做

 foreach($n  as $reach)
        {
          echo $reach['product_id']
        }

它给出错误....帮助...提前致谢

2 个答案:

答案 0 :(得分:1)

试试这个

 foreach($n  as $reach)
 {
    foreach($reach  as $a)
    {
       echo $a['product_id']
    }
  }

答案 1 :(得分:0)

从3d数组中获取product_id,您可以使用此

foreach{$n as  value}
{
   foreach($value as value1)
   {
      foreach($value1 as value2)
      { 
            echo $a['product_id'];
      }
   }
}