foreach循环的数组数量

时间:2013-04-05 06:11:59

标签: php foreach foreach-loop-container

代码:

foreach ($output as $result)
print_r($result);

以下是我上面代码的输出:

Array ( [0] => 323 [1] => 323 [2] => 323 [3] => 323 [4] => 65 [5] => 65 [6] => 65 [7] => 65 [8] => 121 [9] => 121 [10] => 121 [11] => 121 ) 
Array ( ) 
Array ( ) 
Array ( [0] => 656 [1] => 656 [2] => 656 [3] => 656 ) 
Array ( [0] => 777 [1] => 777 [2] => 777 [3] => 777 ) 
Array ( [0] => 321 [1] => 321 [2] => 321 [3] => 321 [4] => 434 [5] => 434 [6] => 434 [7] => 434 [8] => 400 [9] => 400 [10] => 400 [11] => 400 ) 
Array ( ) 
Array ( ) 
Array ( [0] => 300 [1] => 300 [2] => 300 [3] => 300 [4] => 666 [5] => 666 [6] => 666 [7] => 666 ) 
Array ( )
Array ( [0] => 167 [1] => 167 [2] => 167 [3] => 167 )

我想分别打印每个数组。尝试嵌套foreach循环,但没有获得所需的输出。

请帮忙

1 个答案:

答案 0 :(得分:0)

嵌套循环很简单

foreach ($output as $outer)
{
  foreach ($outer as $inner)
  {
    print_r($inner);
  }
}