static function attachChildren(&$array) { $count = count($array); for ($i = 1; $i < $count; $i++) { $found = false; $array[$i - 1] = Arrays::replaceAllParents('!children', $array[$i], $array[$i - 1], 1, $found); if ($found) { //collapse tree array_splice($array, $i - 1, 2, [$array[$i - 1]]); } } return $array; }