数组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));$root = array();foreach($a as $item) { $p =& $root; foreach($item as $k) { if(!isset($p[$k])) $p[$k] = array(); $p =& $p[$k]; }}print_r($root);
Array( [7] => Array ( [5] => Array ( ) [6] => Array ( [1] => Array ( ) [2] => Array ( [3] => Array ( [5] => Array ( ) [6] => Array ( ) ) ) ) ))
帅