如何使用foreach获取这些数组值?

时间:2014-04-16 08:55:36

标签: php yii

Array (
    [4] => Array (
        [0] => priyaa
        [1] => aarthy
    )
    [10] => Array (
        [0] => testa
        [1] => test member 1
    )
)

2 个答案:

答案 0 :(得分:0)

如果您不确定将拥有多少结果,请在循环内部循环。

例如......

$YourArray = array();
//Add to array here.

foreach($YourArray as $LevelOne):
  foreach ($LevelOne as $LevelTwo):
   echo $LevelTwo . ' - ';
  endforeach;
  echo '<br>';
endforeach;

为你输出。

priyaa - aarthy
testa - test member 1

答案 1 :(得分:0)

试试这个并看看它是否能解决你的问题

$array = array (
4 => array ( 
        0 => "priyaa"
        1 => "aarthy"
)
10 => array (
        0 => "testa"
        1 => "test member 1"
    )
);

foreach($array as $arr) {
    foreach($arr as $val) {
        echo $val;
    }
}

干杯!