如何在PHP中引用嵌套数组中的值?

时间:2013-03-30 09:36:45

标签: php sub-array

在PHP中如何在数组下面返回值1,2和3?

$tmpArray =
   array(
       array("one", array(1, 2, 3)),
       array("two", array(4, 5, 6)),
       array("three", array(7, 8, 9)
   )
);

3 个答案:

答案 0 :(得分:1)

$tmpArray[0][1] = array(1, 2, 3)
$tmpArray[0][1][0] = 1
$tmpArray[0][1][1] = 2
$tmpArray[0][1][2] = 3

答案 1 :(得分:0)

试试这个

foreach($tmpArray as $key => $value)
{
    foreach($value as $val)
       echo $val.'<br>';
}

答案 2 :(得分:0)

试试这个 -

foreach($tmpArray as $key => $value)
{
  if(is_array($value)){
    foreach($value as $val)
      if(is_array($val){
        foreach($val as $v)
          echo $v."<br />";
      }
      else
        echo $val.'<br />';
  }
  else
      echo $value."<br />";
}