Recursive traversal of PHP
Array ([0] = = Array ([0] = 1 [catid] = 1 [1] = 0 [pa Rentid] + 0 [2] = = About us [catname] = About us [3] = 4 [Listorder] =& Gt 4 [4] = 0 [Items] = 0 [5] = 1 [Type] = 1 [child] =& Gt Array ([0] = = Array ([0] = 2 [CATID] + 2 [1] = 1 [parentid] =& Gt 1 [2] = = About us [catname] = About us [3] = 1 [Listorder] + 1 [4] = 0 [Items] = 0 [5] = 1 [Type] = 1) [1] = = Array ([0] = 3 [CATID] = 3 [1] = 1 [parentid] + 1 [2 ] = [CatName] [Company honors] [3] = 2 [Listorder] [2] [4] = 0 [Items] = 0 [5] = 1 [type] + 1) [2] = + Ar Ray ([0] = 4 [catid] = 4 [1] = 1 [ParentID] = 1 [2] = = Contact us [CatName] = = Contact us [3] = 3 [Listorder] =& Gt 3 [4] = 0 [Items] = 0 [5] = 1 [Type] = 1) [3] = = Array ( [0] = 5 [CATID] = 5 [1] = 1 [ParentID] + 1 [2] = + Join us [catname] = Join us [3] = 4 [Listorder] = 4 [4] = = 0 [Items] = 0 [5] = 1 [Type] => ; 1) [4] = = Array ([0] => ; 6 [CATID] = 6 [1] = 1 [ParentID] = 1 [2] = = Friendship link [catname] = [3] = 5 [Listorder] [5] [4] = 0 [items] = = 0 [5] = 2 [Type] = 2) ) ))
function Gettree ($arr) {//$row = $arr; foreach ($arr as $k + = $v) {$tree. = '
'. $v [' CatName ']. "; if (Is_array ($v [' child ')]) {$tree. = '
; Traverse the child subarray of foreach ($v [' Children '] as $SV) {$tree. = '
- '. $sv [' CatName ']. "; Gettree ($v [' child ']); if (Is_array ($sv [' child ')]) {$tree. = '
; foreach ($sv [' child '] as $SSV) {$tree. = '
- '. $SSV [' CatName ']. "
"; } $tree. = "
"; } $tree. = " "; }//print_r ($v [' child ']);//Gettree ($v [' child ']); $tree. = "
"; } $tree. = '';} return $tree;}
Reply to discussion (solution)
You don't have recursion! Gettree ($v [' child ']); It's all commented out.
Gettree has a return $tree;
If recursive, you should write $tree. = Gettree ($v [' child ']);
You don't have recursion! Gettree ($v [' child ']); It's all commented out.
Gettree has a return $tree;
If recursive, you should write $tree. = Gettree ($v [' child ']);
Thank you very much, commented out, there is no output no way
Writing $tree. = Gettree ($v [' child ']); Sweat
I said, thank you.