3v4l.org

run code in 300+ PHP versions simultaneously
<?php function shuffleX($arr, $max=3){ $raw=$arr; $x=0; $s=md5('random_string'); while(1){$x++; shuffle($arr); //Build string out of Arr for repeating variables to check $f2=join($s,$arr); $break=true; foreach($raw as $k=>$v){ //Check for repeating variables each Value (forward and Backward) $f=str_repeat($v.$s,$max); $fa=str_repeat($s.$v.'',$max); if(preg_match('#'.$f.'#',$f2) OR preg_match('#'.$fa.'#',$f2)){ $break=false; } } if($break===true){return $arr;} if($x>(count($arr)*1000)){// if nothing found after x Times break or give an empty array return array('unpossible'); } } } $arr=array(1,2,1,1,2,2,1,2,1,2,1); print_r(shuffleX($arr,3)); ?>

preferences:
50.07 ms | 409 KiB | 5 Q