Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有更好的方法在PHP中迭代这个多维数组?_Php_Arrays - Fatal编程技术网

有没有更好的方法在PHP中迭代这个多维数组?

有没有更好的方法在PHP中迭代这个多维数组?,php,arrays,Php,Arrays,我正在使用Solr搜索引擎。它返回我的搜索结果,如下所示: array(2) { ["responseHeader"]=> array(3) { ["status"]=> int(0) ["QTime"]=> int(1) ["params"]=> array(5) { ["wt"]=> string(3) "php" ["start"]=> string(

我正在使用Solr搜索引擎。它返回我的搜索结果,如下所示:

array(2) {
  ["responseHeader"]=>
  array(3) {
    ["status"]=>
    int(0)
    ["QTime"]=>
    int(1)
    ["params"]=>
    array(5) {
      ["wt"]=>
      string(3) "php"
      ["start"]=>
      string(1) "0"
      ["q"]=>
      string(7) "monitor"
      ["version"]=>
      string(3) "2.2"
      ["rows"]=>
      string(2) "10"
    }
  }
  ["response"]=>
  array(3) {
    ["numFound"]=>
    int(2)
    ["start"]=>
    int(0)
    ["docs"]=>
    array(2) {
      [0]=>
      array(11) {
        ["id"]=>
        string(6) "VA902B"
        ["name"]=>
        string(49) "ViewSonic VA902B - flat panel display - TFT - 19""
        ["manu"]=>
        string(15) "ViewSonic Corp."
        ["weight"]=>
        float(190.4)
        ["price"]=>
        float(279.95)
        ["price_c"]=>
        string(10) "279.95,USD"
        ["popularity"]=>
        int(6)
        ["inStock"]=>
        bool(true)
        ["store"]=>
        string(18) "45.17614,-93.87341"
        ["cat"]=>
        array(2) {
          [0]=>
          string(11) "electronics"
          [1]=>
          string(7) "monitor"
        }
        ["features"]=>
        array(1) {
          [0]=>
          string(75) "19" TFT active matrix LCD, 8ms response time, 1280 x 1024 native resolution"
        }
      }
      [1]=>
      array(12) {
        ["id"]=>
        string(7) "3007WFP"
        ["name"]=>
        string(34) "Dell Widescreen UltraSharp 3007WFP"
        ["manu"]=>
        string(10) "Dell, Inc."
        ["includes"]=>
        string(9) "USB cable"
        ["weight"]=>
        float(401.6)
        ["price"]=>
        float(2199)
        ["price_c"]=>
        string(8) "2199,USD"
        ["popularity"]=>
        int(6)
        ["inStock"]=>
        bool(true)
        ["store"]=>
        string(18) "43.17614,-90.57341"
        ["cat"]=>
        array(2) {
          [0]=>
          string(11) "electronics"
          [1]=>
          string(7) "monitor"
        }
        ["features"]=>
        array(1) {
          [0]=>
          string(71) "30" TFT active matrix LCD, 2560 x 1600, .25mm dot pitch, 700:1 contrast"
        }
      }
    }
  }
}
我在一个名为
$results
的变量中捕获这个响应。在我的页面上,我正在执行vardump以获得每个结果集,如下所示:

foreach($results['response'] as $result) {
    if(is_array($result)) {
        foreach($result as $v) {
            var_dump($v);   
        }
    }
}
这是该系统的输出:

array(11) {
  ["id"]=>
  string(6) "VA902B"
  ["name"]=>
  string(49) "ViewSonic VA902B - flat panel display - TFT - 19""
  ["manu"]=>
  string(15) "ViewSonic Corp."
  ["weight"]=>
  float(190.4)
  ["price"]=>
  float(279.95)
  ["price_c"]=>
  string(10) "279.95,USD"
  ["popularity"]=>
  int(6)
  ["inStock"]=>
  bool(true)
  ["store"]=>
  string(18) "45.17614,-93.87341"
  ["cat"]=>
  array(2) {
    [0]=>
    string(11) "electronics"
    [1]=>
    string(7) "monitor"
  }
  ["features"]=>
  array(1) {
    [0]=>
    string(75) "19" TFT active matrix LCD, 8ms response time, 1280 x 1024 native resolution"
  }
}

array(12) {
  ["id"]=>
  string(7) "3007WFP"
  ["name"]=>
  string(34) "Dell Widescreen UltraSharp 3007WFP"
  ["manu"]=>
  string(10) "Dell, Inc."
  ["includes"]=>
  string(9) "USB cable"
  ["weight"]=>
  float(401.6)
  ["price"]=>
  float(2199)
  ["price_c"]=>
  string(8) "2199,USD"
  ["popularity"]=>
  int(6)
  ["inStock"]=>
  bool(true)
  ["store"]=>
  string(18) "43.17614,-90.57341"
  ["cat"]=>
  array(2) {
    [0]=>
    string(11) "electronics"
    [1]=>
    string(7) "monitor"
  }
  ["features"]=>
  array(1) {
    [0]=>
    string(71) "30" TFT active matrix LCD, 2560 x 1600, .25mm dot pitch, 700:1 contrast"
  }
}
这正是我所需要的,但我想知道是否有比我的“嵌套foreach循环和is数组检查”方法更简单的方法来获得它

foreach ($results['response']['docs'] as $result) {
   ...
}