php递归,函数不返回任何值

xia*_*oss -1 php recursion return

我希望我的函数返回整个url,从具有给定id的节点开始,并为父项进行serching,最后一个具有parent_id = 1.我的功能几乎可以工作,回显"$ wholeUrl"; 我有我的网址,但功能不会重新调整它,我不知道wtf,请帮忙.

这是我的代码:

function getUrl($ xml,$ id){

$wholeUrl="";
$wholeUrl= getMyUrl($xml,$id,$wholeUrl);
return $wholeUrl;
Run Code Online (Sandbox Code Playgroud)

}

function getMyUrl($ xml,$ idWew,$ wholeUrl){

foreach($xml as $node) {
    $par = $node->parent_id;
    $ide = $node->id;
    $url = $node->url;
    $name = $node->name;
    settype($par,'integer');
    settype($ide,'integer');

    if($ide==$idWew){

        $wholeUrl=$url."/".$wholeUrl;

        if($par==1){
            echo"$wholeUrl ";
            return $wholeUrl;
            break;
        }else{

            getMyUrl($xml,$par,$wholeUrl);
        }
    }

}
}


print_r(getUrl($xmlcat,1877));
Run Code Online (Sandbox Code Playgroud)

$ xmlcat是具有以下结构的平面数组:

SimpleXMLElement Object ( [id] => 1876 [parent_id] => 1 [name] => blablabla, bla, bla [url] => bla-bla-bla-bla ) 
Run Code Online (Sandbox Code Playgroud)

Pha*_*aoh 5

你需要返回getMyUrl:

    /* .... */
    }else{

        return getMyUrl($xml,$par,$wholeUrl);
    }
    /* .... */
Run Code Online (Sandbox Code Playgroud)