3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $data = array( array('f1', 'f2', 'f3'), array('s1', 's2', 's3', 's4', 's5'), array('t1', 't2', 't3', 't4', 't5', 't6', 't7', 't8', 't9', 't10', 't11', 't12') ); $max = 12; $each = $max / count($data); $result = array(); foreach ($data as $set) { $start = count($result); while (count($set) > 0 && (count($result)-$start) <= $max) { $result[] = array_shift($set); } } print_r($result);
Output for 4.3.0 - 7.1.0
Array ( [0] => f1 [1] => f2 [2] => f3 [3] => s1 [4] => s2 [5] => s3 [6] => s4 [7] => s5 [8] => t1 [9] => t2 [10] => t3 [11] => t4 [12] => t5 [13] => t6 [14] => t7 [15] => t8 [16] => t9 [17] => t10 [18] => t11 [19] => t12 )