stuzer05 hat die Gist bearbeitet . Zu Änderung gehen
1 file changed, 17 insertions
index.php(Datei erstellt)
@@ -0,0 +1,17 @@ | |||
1 | + | function buildTree(array $elements, $parentId = 0) { | |
2 | + | $branch = array(); | |
3 | + | ||
4 | + | foreach ($elements as $element) { | |
5 | + | if ($element['parent_id'] == $parentId) { | |
6 | + | $children = buildTree($elements, $element['id']); | |
7 | + | if ($children) { | |
8 | + | $element['children'] = $children; | |
9 | + | } | |
10 | + | $branch[] = $element; | |
11 | + | } | |
12 | + | } | |
13 | + | ||
14 | + | return $branch; | |
15 | + | } | |
16 | + | ||
17 | + | $tree = buildTree($rows); |
Neuer
Älter