public static function orderByParents($data, $posible = [])
{
$total = count($data);
$num = 0;
$list = '';
$array = [];
if (count($posible)) {
foreach ($data as $row) {
$row['sub'] = [];
if (!$row['category_id'] && array_key_exists($row['id'], $posible)) {
$row['numProducts'] = $posible[$row['id']];
$array[] = $row;
$num++;
$list .= $row['id'] . '-';
}
}
} else {
foreach ($data as $row) {
$row['sub'] = [];
if (!$row['category_id']) {
$array[] = $row;
$num++;
$list .= $row['id'] . '-';
}
}
}
if ($num < $total) {
for ($i = 0; $i < count($array); $i++) {
self::findChildren($array[$i], $data, $list, false, $posible);
}
}
return $array;
}