我如何在PHP中迭代这种类型的数组

时间:2010-10-23 23:38:11

标签: php

array(2) {
  ["param"]=>
  array(1) {
    ["stuNBR"]=>
    string(5) "555555"
  }
  ["data"]=>
  array(3) {
    [0]=>
    array(6) {
      ["SEQNBR"]=>
      string(1) "2"
      ["CDE"]=>
      string(3) "MUG"
      ["NBR1"]=>
      string(1) "1"
      ["NBR2"]=>
      string(1) "0"
      ["NBR3"]=>
      string(3) "PAN"
      ["NBR4"]=>
      string(1) "Y"
    }
    [1]=>
     array(6) {
      ["SEQNBR"]=>
      string(1) "2"
      ["CDE"]=>
      string(3) "JUG"
      ["NBR1"]=>
      string(1) "1"
      ["NBR2"]=>
      string(1) "0"
      ["NBR3"]=>
      string(3) "RAN"
      ["NBR4"]=>
      string(1) "Y"
    }   
    [2]=>
     array(6) {
      ["SEQNBR"]=>
      string(1) "2"
      ["CDE"]=>
      string(3) "GHY"
      ["NBR1"]=>
      string(1) "1"
      ["NBR2"]=>
      string(1) "0"
      ["NBR3"]=>
      string(3) "PAN"
      ["NBR4"]=>
      string(1) "Y"
    }
   }
}

如何从上面迭代“数据”数组并获取NBR1和NBR2值

foreach ($this->bigarray['DEFAULTS'] as $data){
   echo $data['NBR1']."---->".$data['NBR2'];
}

我如何获得这些价值

1 个答案:

答案 0 :(得分:6)

您可以使用嵌套循环:

foreach ($this->bigarray['data'] as $data){
   foreach($data as $k => $v) {
      echo $k."---->".$v;
   }
}