php簡(jiǎn)單實(shí)現(xiàn)無限分類樹形列表的方法
本文實(shí)例講述了php簡(jiǎn)單實(shí)現(xiàn)無限分類樹形列表的方法。分享給大家供大家參考。具體如下:
$items = array(
1 => array('id' => 1, 'pid' => 0, 'name' => '江西省'),
2 => array('id' => 2, 'pid' => 0, 'name' => '黑龍江省'),
3 => array('id' => 3, 'pid' => 1, 'name' => '南昌市'),
4 => array('id' => 4, 'pid' => 2, 'name' => '哈爾濱市'),
5 => array('id' => 5, 'pid' => 2, 'name' => '雞西市'),
6 => array('id' => 6, 'pid' => 4, 'name' => '香坊區(qū)'),
7 => array('id' => 7, 'pid' => 4, 'name' => '南崗區(qū)'),
8 => array('id' => 8, 'pid' => 6, 'name' => '和興路'),
9 => array('id' => 9, 'pid' => 7, 'name' => '西大直街'),
10 => array('id' => 10, 'pid' => 8, 'name' => '東北林業(yè)大學(xué)'),
11 => array('id' => 11, 'pid' => 9, 'name' => '哈爾濱工業(yè)大學(xué)'),
12 => array('id' => 12, 'pid' => 8, 'name' => '哈爾濱師范大學(xué)'),
13 => array('id' => 13, 'pid' => 1, 'name' => '贛州市'),
14 => array('id' => 14, 'pid' => 13, 'name' => '贛縣'),
15 => array('id' => 15, 'pid' => 13, 'name' => '于都縣'),
16 => array('id' => 16, 'pid' => 14, 'name' => '茅店鎮(zhèn)'),
17 => array('id' => 17, 'pid' => 14, 'name' => '大田鄉(xiāng)'),
18 => array('id' => 18, 'pid' => 16, 'name' => '義源村'),
19 => array('id' => 19, 'pid' => 16, 'name' => '上壩村'),
20 => array('id' => 20, 'pid' => 0, 'name' => '廣東省'),
21 => array('id' => 21, 'pid' => 20, 'name' => '廣州市'),
);
$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 "<pre>";
print_r($items);
希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。
相關(guān)文章
php使用pdo連接報(bào)錯(cuò)Connection failed SQLSTATE的解決方法
這篇文章主要介紹了php使用pdo連接報(bào)錯(cuò)Connection failed SQLSTATE的解決方法,涉及針對(duì)配置文件的修改,具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2014-12-12
php Undefined index和Undefined variable的解決方法
這段時(shí)間在做項(xiàng)目過程中老是出現(xiàn)這個(gè)提示,起初是用$act來接受表單post過來的數(shù)據(jù)2008-03-03
PHP實(shí)現(xiàn)的簡(jiǎn)單操作SQLite數(shù)據(jù)庫(kù)類與用法示例
這篇文章主要介紹了PHP實(shí)現(xiàn)的簡(jiǎn)單操作SQLite數(shù)據(jù)庫(kù)類與用法,結(jié)合具體實(shí)例形式分析了php封裝的針對(duì)SQLite數(shù)據(jù)庫(kù)相關(guān)增刪改查操作技巧與使用方法,需要的朋友可以參考下2017-06-06
php結(jié)合md5實(shí)現(xiàn)的加密解密方法
這篇文章主要介紹了php結(jié)合md5實(shí)現(xiàn)的加密解密方法,涉及PHP字符串操作及加密解密算法實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-01-01
淺析關(guān)于PHP位運(yùn)算的簡(jiǎn)單權(quán)限設(shè)計(jì)
本篇文章是對(duì)PHP位運(yùn)算的簡(jiǎn)單權(quán)限設(shè)計(jì)進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
PHP寫MySQL數(shù)據(jù) 實(shí)現(xiàn)代碼
非常簡(jiǎn)單的php操作數(shù)據(jù)庫(kù)代碼,其實(shí)就是添加一條記錄啊,入門的朋友可以看看。2009-06-06
PHP實(shí)現(xiàn)登錄搜狐廣告獲取廣告聯(lián)盟數(shù)據(jù)的方法【附demo源碼】
這篇文章主要介紹了PHP實(shí)現(xiàn)登錄搜狐廣告獲取廣告聯(lián)盟數(shù)據(jù)的方法,涉及php基于curl的遠(yuǎn)程數(shù)據(jù)操作相關(guān)技巧,需要的朋友可以參考下2016-10-10

