php树形结构显示
数组array(array(7,5),array(7,6,1),array(7,6,2,3,5),array(7,6,2,3,6))
在前端想显示成树形,请问如何处理?
------解决思路----------------------
$a = array(array(7,5),array(7,6,1),array(7,6,2,3,5),array(7,6,2,3,6));<br /><br />$root = array();<br />foreach($a as $item) {<br /> $p =& $root;<br /> foreach($item as $k) {<br /> if(!isset($p[$k])) $p[$k] = array();<br /> $p =& $p[$k];<br /> }<br />}<br />print_r($root);<br />
Array<br />(<br /> [7] => Array<br /> (<br /> [5] => Array<br /> (<br /> )<br /><br /> [6] => Array<br /> (<br /> [1] => Array<br /> (<br /> )<br /><br /> [2] => Array<br /> (<br /> [3] => Array<br /> (<br /> [5] => Array<br /> (<br /> )<br /><br /> [6] => Array<br /> (<br /> )<br /><br /> )<br /><br /> )<br /><br /> )<br /><br /> )<br /><br />)<br /><br />