您好,登錄后才能下訂單哦!
這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)?lái)有關(guān)PHP中怎么實(shí)現(xiàn)數(shù)組無(wú)限極分類(lèi),文章內(nèi)容豐富且以專(zhuān)業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
<?php $data = array( 1 => array('id' => 1,'name' => 'name1','pid' => 0), 2 => array('id' => 2,'name' => 'name2','pid' => 0), 3 => array('id' => 3,'name' => 'name3','pid' => 1), 4 => array('id' => 4,'name' => 'name4','pid' => 0), 5 => array('id' => 5,'name' => 'name5','pid' => 3), 6 => array('id' => 6,'name' => 'name6','pid' => 3), ); $str = getTree(0); $str = "<select name='term'>" . $str . "</select>"; echo $str; function getTree($id,$spac=0) { $data = array( 1 => array('id' => 1,'name' => 'name1','pid' => 0), 2 => array('id' => 2,'name' => 'name2','pid' => 0), 3 => array('id' => 3,'name' => 'name3','pid' => 1), 4 => array('id' => 4,'name' => 'name4','pid' => 0), 5 => array('id' => 5,'name' => 'name5','pid' => 3), 6 => array('id' => 6,'name' => 'name6','pid' => 3), ); $spac = $spac + 2; static $str; foreach ($data as $k => $v) { if ($v['pid'] == $id) { $arr[] = $v; $str .= "<option value='" . $v['id'] . "'>" . str_repeat(" ",$spac) . "|--" . $v['name'] . "</option>"; getTree($v['id'],$spac); } } return $str; } ?>
效果如圖
上述就是小編為大家分享的PHP中怎么實(shí)現(xiàn)數(shù)組無(wú)限極分類(lèi)了,如果剛好有類(lèi)似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。