Php多维数组从具有不同键的数组中获取值

时间:2015-11-01 03:13:35

标签: php

我需要帮助。我有一个数组:

$A = 
    array(
        "0" =>
            array(
                "1" => array('name' => '1234', 'value' => '1'),
                "2" => array('name' => '5678', 'value' => '8')
            ),
        "1" =>
            array(
                "1" => array('name' => '5678', 'value' => '5')
            )
    );

如果数组键value值为name,如何从数组中获取5678(在foreach循环中)?

2 个答案:

答案 0 :(得分:3)

希望这会有所帮助

foreach ($A as $B) {
 foreach ($B as $C) {
    if ($C['name'] == '5678') {
       echo $C['value'].'<br>';
    }
  }
}

答案 1 :(得分:0)

您可以这样做:

foreach ($A as $array_item) {
  foreach ($array_item as $inner_array) {
      if ($inner_array['name'] == '5678') {
          var_dump($inner_array['value']);
      }   
  }   
}