0

我似乎可以让该方法返回一个数组。我可以在 myRecursiveFunction 返回之前获得 var_dump

if($return){
            var_dump($myArray);
            return $myArray;
        }

但是在调用函数中我的 var_dump 是空的....不知道我做错了什么

private function myCallingFunction(){

            $x = $this->myRecursiveFunction();
var_dump($x);

    }

private function myRecursiveFunction($next = null, $recursion = false, $myArray = array())
{
    $return = false;
    if (!$recursion) {

        $result = json_decode($this->getMyResults);
        $myArray = $result->myResults;
        if ($result->getMore) {
            $this->myRecursiveFunction($result->getMore, true, $myArray);
            $return = false;
        }else{
            $return = true;
        }
    } else {
        $result = json_decode($this->getMyResults);
        $myArray = array_merge($myArray,$result->myResults);
        if ($result->getMore) {
            $this->myRecursiveFunction($result->getMore, true, $myArray);
            $return = false;
        }else{
            $return = true;
        }
    }
    if($return){
        var_dump($myArray);
        return $myArray;
    }

}
4

1 回答 1

0

只需要这样做

return $this->myRecursiveFunction($result->getMore, true, $myArray);
于 2013-10-29T17:24:05.637 回答