Skip to content

Commit 4425fd5

Browse files
committed
optimize ListToTree
1 parent 10d9ff4 commit 4425fd5

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/ListToTree.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,12 @@ public function toTree()
3636
$data = $this->list;
3737
foreach ($data as $d) {
3838
$items[$d[$this->node_index]] = $d;
39-
if (!isset($d[$this->parent_index]) || !isset($d[$this->node_index]) || isset($d[$this->node_name])) {
40-
return false;
41-
}
4239
}
4340
$tree = [];
4441
$n = 0;
45-
foreach ($items as $item) {
42+
foreach ($items as $node_index => $item) {
4643
if (isset($items[$item[$this->parent_index]])) {
47-
$items[$item[$this->parent_index]][$this->node_name][] = &$items[$item[$this->node_index]];
44+
$items[$item[$this->parent_index]][$this->node_name][] = &$items[$node_index];
4845
} else {
4946
$tree[$n++] = &$items[$item[$this->node_index]];
5047
}

0 commit comments

Comments
 (0)