3v4l.org

run code in 300+ PHP versions simultaneously
<?php $albums = ['1','2','3','4','5','6','7','8','9','10','11','12']; $incr = 1; $section_id = 1; $sections = []; foreach ($albums as $album) { $small = ($incr % 2 == 0 && $section_id % 2 != 0) || $incr % 3 == 0; if ($section_id % 2 == 0) { $small = !$small; } $sections[$section_id][($small ? 'small' : 'big')][] = [ 'id' => $album, ]; if ($incr % 3 == 0) { $section_id++; } $incr++; } print_r($sections);

preferences:
52.92 ms | 402 KiB | 5 Q