Php tree structure for unlimited classification-PHP source code

Source: Internet
Author: User
Php implements an infinitely classified tree structure tree. php

 Array ('id' => 1, 'pid '=> 0, 'name' => 'jiangxi province'), 2 => array ('id' => 2, 'pid '=> 0, 'name' => 'heilongjiang province'), 3 => array ('id' => 3, 'pid '=> 1, 'name' => 'nanchang city '), 4 => array ('id' => 4, 'pid' => 2, 'name' => 'Harbin '), 5 => array ('id' => 5, 'pid '=> 2, 'name' => 'jixi city '), 6 => array ('id' => 6, 'pid '=> 4, 'name' => 'xiangfang region '), 7 => array ('id' => 7, 'pid '=> 4, 'name' => 'nangang '), 8 => array ('id' => 8, 'pid '=> 6, 'name' =>' and Xinglu '), 9 => array ('id' => 9, 'pid '=> 7, 'name' => 'westbrook street '), 10 => array ('id' => 10, 'pid '=> 8, 'name' => 'Northeast forestry Emy '), 11 => array ('id' => 11, 'pid '=> 9, 'name' => 'Harbin Institute of Technology '), 12 => array ('id' => 12, 'pid '=> 8, 'name' => 'Harbin Normal University '), 13 => array ('id' => 13, 'pid '=> 1, 'name' => 'ganzhou city '), 14 => array ('id' => 14, 'pid '=> 13, 'name' => 'ganxian '), 15 => array ('id' => 15, 'pid '=> 13, 'name' => 'yudu County '), 16 => array ('id' => 16, 'pid '=> 14, 'name' => 'moudian Zhen '), 17 => array ('id' => 17, 'pid' => 14, 'name' => 'tagname '), 18 => array ('id' => 18, 'pid '=> 16, 'name' => 'yiyuan cune '), 19 => array ('id' => 19, 'pid '=> 16, 'name' => 'shangba cune'),); echo"
"; Print_r (genTree5 ($ items); print_r (genTree9 ($ items); // The latter output format. the former format is similar, but the array key values are different, however, the data structure is not affected./* Array ([0] => Array ([id] => 1 [pid] => 0 [name] => Jiangxi [son] => Array ([0] => Array ([id] => 3 [pid] => 1 [name] => Nanchang City) [1] => Array ([id] => 13 [pid] => 1 [name] => Ganzhou [son] => Array ([0] => Array ([ id] => 14 [pid] => 13 [name] => Ganxian [son] => Array ([0] => Array ([id] => 16 [pid] => 14 [name] => moudian town [son] => Array ([0] => Array ([id] => 18 [pid] => 16 [name] => Yiyuan village) [1] => Array ([id] => 19 [pid] => 16 [name] => Shangba village ))) [1] => Array ([id] => 17 [pid] => 14 [name] => Datian ))) [1] => Array ([id] => 15 [pid] => 13 [name] => Yudu County ))))) [1] => Array ([id] => 2 [pid] => 0 [name] => Heilongjiang [son] => Array ([0] => Array ([ id] => 4 [pid] => 2 [name] => Harbin [son] => Array ([0] => Array ([id] => 6 [pid] => 4 [name] => Xiangfang district [son] => Array ([0] => Array ([id] => 8 [pid] => 6 [name] => hexing Road [son] => Array ([0] => Array ([id] => 10 [pid] => 8 [name] => Northeast Forestry University) [1] => Array ([id] => 12 [pid] => 8 [name] => Harbin Normal University ))))) [1] => Array ([id] => 7 [pid] => 4 [name] => Nangang district [son] => Array ([0] => Array ([ id] => 9 [pid] => 7 [name] => westbound street [son] => Array ([0] => Array ([id] => 11 [pid] => 9 [name] => Harbin Institute of Technology ))))))) [1] => Array ([id] => 5 [pid] => 2 [name] => Jixi city ))))*/

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.