I have following array:
Array
(
[1] => 0
[2] => 1
[3] => 2
[4] => 3
[5] => 1
[6] => 0
)
keys of this array is unique, and values showing parent of key. like parent of 1 & 6 is 0, parent of 2 is 1, for 3 is 2....
I was writing a recursive function which will find a tree view for given parent id. here is my code:
function recurviceChild($parent, $childParent, $resultArr = array()) {
foreach ($childParent as $key => $parentId) {
if ($parent == $parentId) {
$resultArr[$parentId][] = $key;
$resultArr = $this->recurviceChild($key, $childParent, $resultArr);
}
}
return $resultArr;
}
The function I created give me result for depth of level one. result of this function if i call it for $parent=1 ($childParent is array given above) is:
Array
(
[1] => Array
(
[0] => 2
[1] => 5
)
[2] => Array
(
[0] => 3
)
[3] => Array
(
[0] => 4
)
)
I m expecting result like this:
Array
(
[1] => Array
(
[2] => Array
(
[3] => Array
(
[0] => 4
)
)
)
[2] => 5
)
or something that help me to create a tree view. Thank you in advance.