Unlimited class list, level Category List _php tutorial

Source: Internet
Author: User

Unlimited category list, level category list


 PhpHeader("content-type:text/html; Charset=utf-8 ");$arr=Array(    0=>Array(' Id ' =>1, ' Name ' = ' file Management ', ' Pid ' =>0), 1=>Array(' Id ' =>2, ' Name ' = ' source management ', ' Pid ' =>0), 2=>Array(' Id ' =>3, ' Name ' = ' + ' file add ', ' Pid ' =>1), 3=>Array(' Id ' =>4, ' Name ' = ' = ' file delete ', ' Pid ' =>1), 4=>Array(' Id ' =>5, ' Name ' = ' People list ', ' Pid ' =>2), 5=>Array(' Id ' =>6, ' Name ' = ' Add user ', ' Pid ' =>5), 6=>Array(' Id ' =>7, ' Name ' = ' edit user ', ' Pid ' =>5),);functionGettree ($arr,$pid=0,$deep=0){    Static $tree=Array(); foreach($arr  as $k=$row)    {        if($row[' Pid '] = =$pid )        {            $row[' deep '] =$deep; $tree[] =$row; unset($arr[$k]); Gettree ($arr,$row[' Id '],$deep+1); }    }    return $tree;}$res= Gettree ($arr);Echo"
"; Print_r ($res);

Operation Result:

http://www.bkjia.com/PHPjc/1128374.html www.bkjia.com true http://www.bkjia.com/PHPjc/1128374.html techarticle Unlimited class list, level category list? PHP header ("content-type:text/html; Charset=utf-8 "); $arr = Array (0= array (' ID ' =1, ' Name ' = ' file Management ', ' Pid ' =0), 1= array (' ID ' =2, ' ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.