Home >Backend Development >PHP Tutorial >php树形结构显示

php树形结构显示

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-23 13:41:211205browse

数组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                                        (                                        )                                )                        )                )        ))

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn