Php simple method to implement an infinite classification tree list

Source: Internet
Author: User
This article mainly introduces php's simple method of implementing an infinite classification tree list. The example analyzes php's skill of implementing tree lists through arrays, which has some reference value. For more information, see

This article mainly introduces php's simple method of implementing an infinite classification tree list. The example analyzes php's skill of implementing tree lists through arrays, which has some reference value. For more information, see

The example in this article describes how php simply implements an infinite classification tree list. Share it with you for your reference. The details are as follows:

$ Items = array (1 => array ('id' => 1, 'pid '=> 0, 'name' => 'jiangxi '), 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 '), 20 => array ('id' => 20, 'pid '=> 0, 'name' => 'guangdong province '), 21 => array ('id' => 21, 'pid '=> 20, 'name' => 'guangzhou'),); $ t = array (); foreach ($ items as $ id => $ item) {if ($ item ['pid ']) {$ items [$ item ['pid '] [$ item ['id'] = & $ items [$ item ['id']; $ t [] = $ id ;}} foreach ($ t as $ u) {unset ($ items [$ u]);} echo"

"; Print_r ($ items );

I hope this article will help you with php programming.

,

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.