PHP实现无限分类树列表的一种方法
$ =数组(
1 =阵列('id' = > 1,'pid ' = 0,'name' = >江西),
2 =阵列('id' = > 2,'pid ' = 0,'name' = >黑龙江),
3 =阵列('id' = > 3,'pid= > 1,'name' = >南昌),
4 =阵列('id' = > 4,'pid= > 2,'name' = >哈尔滨),
5 =阵列('id' = > 5,'pid= > 2,'name' = >鸡西),
6 =阵列('id' = > 6,'pid= > 4,'name' = >香坊),
7 =阵列('id' = > 7,'pid= > 4,'name' = >南岗),
8 =阵列('id' = > 8,'pid= > 6,'name' = > '和' Xing Lu),
9 =阵列('id' = > 9,'pid= > 7,'name' = >的西大直街),
10 =阵列('id' = > 10,'pid ' = 8,'name' = >东北林业大学),
11 =阵列('id' = > 11,'pid ' = 9,'name' = >哈尔滨工业大学),
12 =阵列('id' = > 12,'pid ' = 8,'name' = >哈尔滨师范大学),
13 =阵列('id' = > 13,'pid= > 1,'name' = >赣州),
14 =阵列('id' = > 14,'pid ' = 13,'name' = >赣县),
15 =阵列('id' = > 15,'pid= > 13,'name' = >于都),
16 =阵列('id' = > 16,'pid= > 14,'name' = >毛振),
17 =阵列('id' = > 17,'pid= > 14,'name' = >笪天翔),
18 =阵列('id' = > 18,'pid= > 16,'name'的= >沂源村),
19 =阵列('id' = > 19,'pid= > 16,'name' = >村),
20 =阵列('id' = > 20,'pid ' = 0,'name' = >广东),
21 =阵列('id' = > 21,'pid= > 20,'name' = >广州),
);
数组();
foreach(美元美元美元项目ID =项目){
如果($项{ 'pid ' }){
$项目{ $项{ } } { $项'pid{ 'id' } } = $项目{ $项{ 'id' } };
$ $;
}
}
foreach($ T $ U){
unset($项目{ $ U });
}
;
print_r($项目);
希望本文能对大家的PHP程序设计有所帮助。