Life Lei Dog---infinite pole classification NO3

Source: Internet
Author: User

<?phpheader ("Content-type:text/html;charset=utf-8");/* Infinite class classification. 2 applications involved 0-Find the sub-column of the designated column 1 is-find the descendants of the designated column, that is, descendants of the tree 2 is-find the parent column of the designated column/Parent column .... Top column, the family tree */$aarr  = array (Array (' ID ' =>1, ' name ' = ' Anhui ', ' pid ' =>0), array (' ID ' =>2, ' name ' = = ') Haidian ', ' pid ' =>7), array (' ID ' =>3, ' name ' = ' raccoon County ', ' pid ' =>5), array (' ID ' =>4, ' name ' = ' changping ', ' pid ' =>7), Array (' ID ' =>5, ' name ' = ' Huaibei ', ' pid ' =>1), array (' ID ' =>6, ' name ' = ' Chaoyang ', ' pid ' =>7), array (' ID ' =>7, ' Name ' = ' + ' Beijing ', ' pid ' =>0), array (' ID ' =>8, ' name ' = ' on ', ' pid ' =>2)); Function subtree ($arr, $id =0,$ lev=1) {$subs  = array ();  //descendant tree foreach ($arr  as  $v) {if ($v [' pid '] ==  $id) {$v [' Lev '] =  $lev; $subs [] =  $v; $subs  = array_merge ($subs, subtree ($arr, $v [' id '], $lev +1 );//array_merge let the array stick up}}return  $subs;} $tree  = subtree ($aarr, 0,1), foreach ($tree  as  $v) {echo str_repeat (' &nbsp;&nbsp; ') , $v [' Lev ']). $v [' name ']. ' <br/> ';//str_repeat replacement}


The previous lesson was to use the static method here is not practical static, but using Array_merge to achieve the effect

This article is from the "Kill Thunder Dog Blog" blog, please be sure to keep this source http://leigood.blog.51cto.com/10796867/1705828

Life Lei Dog---infinite pole classification NO3

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.