PHP implementation recursive and Infinite classification method, PHP implementation of recursive classification
In this paper, we describe the recursive and infinite classification method of PHP, and share it for your reference. The implementation method is as follows:
<?phpecho ""; $area = array (' ID ' =>1, ' area ' = ' Beijing ', ' pid ' =>0), array (' ID ' =>2, ' area ' = ' Guangxi ', ' pid ' =>0), Array (' ID ' =>3, ' area ' = ' Guangdong ', ' pid ' =>0), array (' ID ' =>4, ' area ' = ' Fujian ', ' pid ' =>0), array (' ID ' =>11, ' Area ' = ' Chaoyang ', ' pid ' =>1 ', array (' ID ' =>12, ' area ' = ' Haidian ', ' pid ' =>1), array (' ID ' =>21, ' area ' = ') Nanning ', ' pid ' =>2), array (' ID ' =>45, ' area ' + ' Fuzhou ', ' pid ' =>4), array (' ID ' =>113, ' area ' = ' Asian Games Village ', ' pid ' = >11), array (' ID ' =>115, ' area ' = ' Olympic Village ', ' pid ' =>11), array (' ID ' =>234, ' area ' = ' wuming county ', ' pid ' =>21 '); function T ($arr, $pid =0, $lev =0) {Static $list = Array (), foreach ($arr as $v) {if ($v [' pid ']== $pid) { echo str_repeat (" c1/> ", $lev). $v [' area ']."
"; The output here is to see the effect $list [] = $v; T ($arr, $v [' id '], $lev + 1); } } return $list;} $list = t ($area); echo "
";p Rint_r ($list);? >
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/959117.html www.bkjia.com true http://www.bkjia.com/PHPjc/959117.html techarticle PHP Implementation of recursive and infinite classification method, PHP implementation of recursive classification in this paper, the implementation of PHP recursive and Infinite classification method, share for everyone for reference. The concrete implementation method is as follows ...