小编Mar*_*man的帖子

递归地搜索数组中的键

private function find($needle, $haystack) {
    foreach ($haystack as $name => $file) {
        if ($needle == $name) {
            return $file;
        } else if(is_array($file)) { //is folder
            return $this->find($needle, $file); //file is the new haystack
        }               
    }

    return "did not find";
}
Run Code Online (Sandbox Code Playgroud)

嘿,此方法在关联数组中搜索特定键并返回与其关联的值.递归有一些问题.任何线索?

php arrays recursion search

20
推荐指数
3
解决办法
2万
查看次数

标签 统计

arrays ×1

php ×1

recursion ×1

search ×1