Created
April 14, 2017 10:43
-
-
Save devd123/6ab4943f784267ed06b25b08fd9e2dde to your computer and use it in GitHub Desktop.
Parent Child Tree PHP Recursion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function getresultTree(array $elements, $parentId = 0) { | |
$branch = array(); | |
foreach ($elements as $element) { | |
if ($element['parent_id'] == $parentId) { | |
$children = getresultTree($elements, $element['id']); | |
if ($children) { | |
$element['child'] = $children; | |
} | |
$branch[] = $element; | |
} | |
} | |
return $branch; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When i was facing the same problem and searching the solution, i got my soloution here. You can check this link too may be useful ( https://kodlogs.net/265/php-recursive-function-to-generate-a-parent-child-tree )