3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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);
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.2.0
Array ( [1] => Array ( [big] => Array ( [0] => Array ( [id] => 1 ) ) [small] => Array ( [0] => Array ( [id] => 2 ) [1] => Array ( [id] => 3 ) ) ) [2] => Array ( [small] => Array ( [0] => Array ( [id] => 4 ) [1] => Array ( [id] => 5 ) ) [big] => Array ( [0] => Array ( [id] => 6 ) ) ) [3] => Array ( [big] => Array ( [0] => Array ( [id] => 7 ) ) [small] => Array ( [0] => Array ( [id] => 8 ) [1] => Array ( [id] => 9 ) ) ) [4] => Array ( [small] => Array ( [0] => Array ( [id] => 10 ) [1] => Array ( [id] => 11 ) ) [big] => Array ( [0] => Array ( [id] => 12 ) ) ) )