0
我想通過填充引用數組來生成一個使用遞歸邏輯的集合,但我並沒有那麼穩定的引用語法。下面的例子是否有意義? (我瞭解如何正確使用這個操作符?)如果沒有,如何做到這一點?遞歸函數引用集合
// I want all uniquely named subfolders returned as array
$allFolders = recursive('/');
function recursive($folder,$collection=array())
{
/* Look up direct children here */
foreach ($subFolders as $folder) {
if (!isset($collection[$folder])) {
$collection[$folder] = $folder;
recursive($folder,&$collection);
}
}
return $collection;
}
另外要小心,PHP並不真正喜歡遞歸。您可能想嘗試一種迭代方法。 –
什麼是最有效的方式來做我想要完成的事情? –