3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php //16 $arr = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p"); $limit=7; $count=ceil(count($arr)/$limit); $content = array(); $j=1; for($i=0;$i<$count;$i++) { $content[$i] = array_slice($arr,($i*$limit),($j*$limit)); //ambil array yang pertama dari setiap limit array. $tmpContent= array(); if($content[$i][0]!=$content[$i]) { $tmpContent[$i] = $content[$i]; } $content[$i] = array($content[$i][0],$tmpContent[$i]); //$content[$i][0] = array($content[$i][0]); $j++; } echo "<pre>"; var_dump(array_chunk($arr,7)); echo "</pre>";
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
<pre>array(3) { [0]=> array(7) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" [3]=> string(1) "d" [4]=> string(1) "e" [5]=> string(1) "f" [6]=> string(1) "g" } [1]=> array(7) { [0]=> string(1) "h" [1]=> string(1) "i" [2]=> string(1) "j" [3]=> string(1) "k" [4]=> string(1) "l" [5]=> string(1) "m" [6]=> string(1) "n" } [2]=> array(2) { [0]=> string(1) "o" [1]=> string(1) "p" } } </pre>