3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 'one', 'two', 'three', 'four' ]; $n = 10; $result = []; for ($x = 0; $x < $n; $x += (int) (!$x || $result[$x] !== $result[$x - 1])) { $result[$x] = $array[array_rand($array)]; } echo json_encode($result);

preferences:
39.31 ms | 405 KiB | 5 Q