递归函数返回错误500

时间:2017-06-29 11:47:17

标签: php arrays recursion

我创建递归函数以在$allCategories数组上行走,但它给出了错误500.错误日志/var/log/httpd/domains/mydomain.com.error.log并显示除通知之外没有显示任何内容的所有错误。我做错了什么?

$categoryArray = $this->searchNodes($allCategories,$category->id);

public function searchNodes($tree,$search_id){  
    foreach($tree as $array){
            if($array['id_category'] == $search_id){
                return $array;
            } else{
                if(array_key_exists('children', $array))
                    $childrenNodes = $this->searchNodes($array['children'],$search_id);
                    if($childrenNodes != false){
                        return $childrenNodes;
                    }
            }
    }
    return false;
}

0 个答案:

没有答案