3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function restructureArray3($array, $x) { while ($x) $return [] = implode(', ', array_splice($array, 0, ceil(sizeof($array) / $x--))); return $return; } $array = range(1, 8); $x = 3; var_dump(restructureArray3($array, $x));
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(3) { [0]=> string(7) "1, 2, 3" [1]=> string(7) "4, 5, 6" [2]=> string(4) "7, 8" }