On the basis of some sort to make some arrays?

The subject is not very clear, I will explain in more detail
There is a array which has the sort field:
Array
(
 [0] => Array
(
 [title] => 1507540823
 [sort] => 100
)

 [1] => Array
(
 [title] => 1507540823
 [sort] => 110
)

 [2] => Array
(
 [title] => 1507540823
 [sort] => 120
)

 [3] => Array
(
 [title] => 1507540823
 [sort] => 200
)

 [4] => Array
(
 [title] => 1507540823
 [sort] => 210
)

)

Need to get this:
Array
(
 [0] => Array
(
 [0] => Array
(
 [title] => 1507540905
 [sort] => 100
)

 [1] => Array
(
 [title] => 1507540905
 [sort] => 110
)

 [2] => Array
(
 [title] => 1507540905
 [sort] => 120
)

)

 [1] => Array
(
 [0] => Array
(
 [title] => 1507540905
 [sort] => 200
)

 [1] => Array
(
 [title] => 1507540905
 [sort] => 210
)

)

)


I.e. the minimum step of sorting 10. You need all the elements where the value of sotiroski : 100,110,120,190 record in a separate array or an element of a multidimensional array as in the example. 200,210 and so on to another item
June 14th 19 at 18:26
2 answers
June 14th 19 at 18:28
$result = [];
foreach ((array)$array as $arr) {
 if ($arr['sort'] < 200) {
 $result[0][] = $arr;
 } else {
 $result[1][] = $arr;
}
}
June 14th 19 at 18:30
//if it is necessary first to do the sorting
usort($arr, function($a, $b) {
 return $a['sort'] === $b['sort'] ? 0 : ($a['sort'] < $b['sort'] ? -1 : 1);
});

$divisor = 100;
$res = [];
foreach ($arr as $subArr) {
 $res[intdiv($subArr['sort'], $divisor)][] = $subArr;
}
//if php < 7, then change intdiv on the floor and /

Find more questions by tags PHP