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.
,