3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function distribute($players) { $ceil = ceil(count($players) / 2); $floor = floor(count($players) / 2); $ceilArray = array_chunk($players, $ceil); $floorArray = array_chunk($players, $floor); printf('%2d players. ceil %2d - %s'.PHP_EOL, count($players), $ceil, counts($ceilArray)); printf('%2d players. floor %2d - %s'.PHP_EOL, count($players), $floor, counts($floorArray)); } function counts($array) { $out = ''; foreach ($array as $dimension => $elements) { $out .= sprintf('team%d: %d; ', $dimension, count($elements)); } return $out; } distribute(range(1, 9)); distribute(range(1, 10)); distribute(range(1, 11));
Output for 5.6.30, hhvm-3.15.4 - 3.22.0, 7.0.0 - 7.2.11
9 players. ceil 5 - team0: 5; team1: 4; 9 players. floor 4 - team0: 4; team1: 4; team2: 1; 10 players. ceil 5 - team0: 5; team1: 5; 10 players. floor 5 - team0: 5; team1: 5; 11 players. ceil 6 - team0: 6; team1: 5; 11 players. floor 5 - team0: 5; team1: 5; team2: 1;