$arr = [
1 => [
31 => 0,
32 => 0,
],
2 => [
36 => 0,
37 => 0,
38 => 0,
],
3 => [
44 => 0,
45 => 0,
46 => 0,
],
]
$grouped = array_reduce(array_keys($array), function($result, $value) use ($array) {
if ($array[$value] == 0) {
if (count($result)) {
$max_key = max(array_keys($result));
$max_value = max($result[$max_key]);
if ($value - $max_value == 1) {
$result[$max_key][] = $value;
} else {
$result[$max_key + 1] = [$value];
}
} else {
$result[1] = [$value];
}
}
return $result;
}, []);