我从这里的一个问题中得到了这个功能。当我尝试使用单独的文件时,它会正常运行。但是当我在包含更多函数的类中重写它时,我宁愿在另一个文件中调用它,这个函数中包含的 searchRec(调用函数本身)变成红色或被 Visual Studio 代码标记为错误。而之前,在这个函数上面我也写了同一个函数,其中有一个函数调用本身,它运行正常。
public function searchRec($haystack, $needle, $pathId=Array(), $pathIndex=Array())
{
foreach($haystack as $index => $item) {
$pathId[] = $item['Id'];
$pathIndex[] = $index;
if($item['Title'] == $needle) {
$returnObject = new stdClass();
$returnObject->match = $item;
$returnObject->pathId = $pathId;
item directly
$returnObject->pathIndex = $pathIndex;
return $returnObject;
}
if(isset($item['Children']) && count($item['Children']>0)) {
(recursively)
$result = searchRec($item['Children'], $needle, $pathId, $pathIndex); //searchRec error, VCS say: undifined function
if($result) {
return $result;
}
}
}
return false;
}