Jump to content
  • Hello visitors, welcome to the Hacker World Forum!

    Red Team 1949  (formerly CHT Attack and Defense Team) In this rapidly changing Internet era, we maintain our original intention and create the best community to jointly exchange network technologies. You can obtain hacker attack and defense skills and knowledge in the forum, or you can join our Telegram communication group to discuss and communicate in real time. All kinds of advertisements are prohibited in the forum. Please register as a registered user to check our usage and privacy policy. Thank you for your cooperation.

    TheHackerWorld Official

php数组通过递归转换成无限级树结构

 Share


HACK1949

Recommended Posts

   //id作为索引,pid 为父索引
   function tree(&$list,$pid=0){
        $tree=[];
        foreach ($list as $key=>$item){
            if ($item['pid']===$pid){
                $tree[$item['id']]=$item;
                unset($list[key]); //删除当前项,减小递归压力
                $tree[$item['id']]['children']=tree($list,$item['id']); //使用children 接收递归出的子数组
            }
        }
        return $tree;
    }

 

Link to post
Link to comment
Share on other sites

 Share

discussion group

discussion group

    You don't have permission to chat.
    • Recently Browsing   0 members

      • No registered users viewing this page.
    ×
    ×
    • Create New...