3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $a = array(0,1,2); $maxtries = intval(count($a)*(floatval(count($a)+1)/2.0)); $tries = 0; while(!empty($a) && $tries<$maxtries) { echo "Try number: ".($tries+1)."\n"; print_r($a); //if($a[$tries]<$a[$tries+1]) { array_push($a, $a[$tries]); //} unset($a[$tries]); $tries += 1; } echo "done\n"; print_r($a);
based on sQXum
Output for 4.3.0 - 7.2.0
Try number: 1 Array ( [0] => 0 [1] => 1 [2] => 2 ) Try number: 2 Array ( [1] => 1 [2] => 2 [3] => 0 ) Try number: 3 Array ( [2] => 2 [3] => 0 [4] => 1 ) Try number: 4 Array ( [3] => 0 [4] => 1 [5] => 2 ) Try number: 5 Array ( [4] => 1 [5] => 2 [6] => 0 ) Try number: 6 Array ( [5] => 2 [6] => 0 [7] => 1 ) done Array ( [6] => 0 [7] => 1 [8] => 2 )