3v4l.org

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

preferences:
29.25 ms | 406 KiB | 5 Q