我从这里的一个问题中得到了这个功能。当我尝试使用单独的文件时,它会正常运行。但是当我在包含更多函数的类中重写它时,我宁愿在另一个文件中调用它,这个函数中包含的 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;}
1 回答
一只斗牛犬
TA贡献1784条经验 获得超2个赞
由于它是一个类方法,因此您需要使用面向对象的语法来调用它。
$result = $this->searchRec($item['Children'], $needle, $pathId, $pathIndex);
- 1 回答
- 0 关注
- 98 浏览
添加回答
举报
0/150
提交
取消