3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $old_arr=array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20); $size = count($old_arr); print_r($size); for($i=0;$i<=19;$i++){ if ($i<=4){ $a[] = $old_arr[$i]; }elseif ($i>4 && $i<=9){ $b[] = $old_arr[$i]; }elseif ($i>9 && $i<=14){ $c[] = $old_arr[$i]; }elseif ($i>14){ $d[] = $old_arr[$i]; } } print_r($a); print_r($b); print_r($c); print_r($d); $new_arr = array(); $group_order[] = array(); $temp = 0; while(count($new_arr)<$size){ if !empty($group_order){ $temp = $group_order[3]; } foreach ($group_order as $i => $value) { unset($group_order[$i]); } $group_order = array_values($group_order); while(count($group_order)<4){ $x=mt_rand(1,4); if(in_array($x,$group_order) == false && $x != $temp){ $group_order[] = $x; $temp = 0; } } foreach ($group_order as $value){ if ($value == 1){ $idx = mt_rand(0,(count($a)-1)); $new_arr[] = $a[$idx]; unset($a[$idx]); $a = array_values($a); }elseif ($value == 2){ $idx = mt_rand(0,(count($b)-1)); $new_arr[] = $b[$idx]; unset($b[$idx]); $b = array_values($b); }elseif ($value == 3){ $idx = mt_rand(0,(count($c)-1)); $new_arr[] = $c[$idx]; unset($c[$idx]); $c = array_values($c); }elseif ($value == 4){ $idx = mt_rand(0,(count($d)-1)); $new_arr[] = $d[$idx]; unset($d[$idx]); $d = array_values($d); } } } print_r($new_arr); ?>
Output for 5.3.0 - 5.4.21
Parse error: syntax error, unexpected '!', expecting '(' in /in/67RfP on line 27
Process exited with code 255.