Skip to content

Commit 8588eb9

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

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/Utils/Tree.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ class Tree
99
* @param string $primary
1010
* @param string $parent
1111
* @param string $children
12-
* @return array
12+
* @return null|array
1313
* #
1414
*/
1515
public static function toTree($data = [], $primary = 'id', $parent = 'parent_id', $children = 'children')
1616
{
1717
// data is empty
1818
if (count($data) === 0) {
19-
return [];
19+
return null;
2020
}
2121

2222
// parameter missing
23-
if (!isset(head($data)[$primary]) || !isset(head($data)[$parent])){
24-
return [];
23+
if (!array_key_exists($primary, head($data)) || !array_key_exists($parent, head($data))){
24+
return null;
2525
}
2626

2727
$items = array();

0 commit comments

Comments
 (0)