我從這里的一個問題中得到了這個功能。當我嘗試使用單獨的文件時,它會正常運行。但是當我在包含更多函數的類中重寫它時,我寧愿在另一個文件中調用它,這個函數中包含的 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 關注
- 183 瀏覽
添加回答
舉報
0/150
提交
取消