Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.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_Sphinx - Fatal编程技术网

Php 斯芬克斯返回数组和权重。

Php 斯芬克斯返回数组和权重。,php,arrays,sphinx,Php,Arrays,Sphinx,我试图简单地回应返回的重量,并做了一些非常错误的事情 [matches] => Array ( [34] => Array ( [weight] => 1707 [attrs] => Array ( ) ) ) 以下是返回的数据示例: 排

我试图简单地回应返回的重量,并做了一些非常错误的事情

   [matches] => Array
     (
        [34] => Array
            (
                [weight] => 1707
                [attrs] => Array
                    (
                    )

            )

    )
以下是返回的数据示例: 排列 ( [错误]=> [警告]=> [状态]=>0 [字段]=>数组 ( [0]=>短语 ) [attrs]=>数组 ( )

   [matches] => Array
     (
        [34] => Array
            (
                [weight] => 1707
                [attrs] => Array
                    (
                    )

            )

    )
这是获取id的工作代码。这对我来说很有意义

   [matches] => Array
     (
        [34] => Array
            (
                [weight] => 1707
                [attrs] => Array
                    (
                    )

            )

    )
      if ( ! empty($result["matches"]) ) {
      foreach ( $result["matches"] as $doc => $docinfo ) {
            echo "DOC ID:$doc\n";
      }

      print_r( $result );
  }
我尝试了另一个foreach,使用doc id循环并获取重量

   [matches] => Array
     (
        [34] => Array
            (
                [weight] => 1707
                [attrs] => Array
                    (
                    )

            )

    )
foreach $doc as $weight  {
这不管用。我猜我在多维数组中做错了什么,但我不确定如何处理嵌套数组

   [matches] => Array
     (
        [34] => Array
            (
                [weight] => 1707
                [attrs] => Array
                    (
                    )

            )

    )

谢谢

您必须尝试递归函数

   [matches] => Array
     (
        [34] => Array
            (
                [weight] => 1707
                [attrs] => Array
                    (
                    )

            )

    )
$array =array(
    "matches" => array(
        array("weight"=>1707,"attrs"=>array("weight"=>100)),
        array("weight"=>1700,"attrs"=>array("weight"=>170)),
        array("weight"=>10,"attrs"=>array("weight"=>170,"attr"=>array("weight"=>"something other")))
    )
);

function recurse($array){
    foreach ($array as $arr){
        if (is_array($arr)){
            recurse($arr);
        } else {
            echo $arr . "<br>";
        }
    }
}

recurse($array);

是否要从多级数组返回
weight
参数?否。数据结构在那里。我只是想得到1707的值。