Skip to content

Commit 2cc8655

Browse files
authored
Update Tree.php
1 parent 2fda852 commit 2cc8655

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Utils/Tree.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@ class Tree
1414
*/
1515
public static function toTree($data = [], $primary = 'id', $parent = 'parent_id', $children = 'children')
1616
{
17+
// data is empty
1718
if (count($data) === 0) {
1819
return [];
1920
}
2021

22+
// parameter missing
23+
if (!isset(head($data)[$primary]) || !isset(head($data)[$parent])){
24+
return [];
25+
}
26+
2127
$items = array();
2228
foreach ($data as $v) {
23-
$items[$v[$primary]] = $v;
29+
$items[@$v[$primary]] = $v;
2430
}
2531

2632
$tree = array();

0 commit comments

Comments
 (0)