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);
Output for 8.2.4
["two","three","four","three","two","four","one","two","three","one"]
Output for 8.2.3
["two","one","three","one","two","three","four","one","two","four"]
Output for 8.2.2
["one","three","four","two","three","two","three","one","two","four"]
Output for 8.2.1
["four","three","two","four","two","three","four","three","two","one"]
Output for 8.2.0
["three","four","two","four","two","four","two","three","two","three"]
Output for 8.1.17
["two","three","four","two","one","four","two","four","one","four"]
Output for 8.1.16
["two","three","two","four","three","four","three","one","four","two"]
Output for 8.1.15
["two","three","two","three","one","four","one","three","one","three"]
Output for 8.1.14
["two","four","two","one","two","four","three","two","three","one"]
Output for 8.1.13
["four","three","two","three","one","four","three","one","three","one"]
Output for 8.1.12
["one","two","one","three","two","four","two","three","one","four"]
Output for 8.1.11
["three","two","three","one","two","three","four","one","two","one"]
Output for 8.1.10
["three","two","three","four","two","one","four","three","four","three"]
Output for 8.1.9
["three","four","three","four","three","one","four","two","one","three"]
Output for 8.1.8
["four","two","three","one","two","four","three","one","four","three"]
Output for 8.1.7
["four","one","four","two","one","three","two","one","two","one"]
Output for 8.1.6
["two","four","one","two","three","four","two","three","four","two"]
Output for 8.1.5
["two","four","two","one","three","one","four","three","four","one"]
Output for 8.1.4
["two","four","one","two","one","two","four","one","four","two"]
Output for 8.1.3
["three","one","three","two","four","one","four","two","four","two"]
Output for 8.1.2
["three","four","one","three","four","three","two","three","one","two"]
Output for 8.1.1
["two","four","one","four","one","four","three","four","one","three"]
Output for 8.1.0
["three","two","three","four","one","three","two","four","one","two"]
Output for 8.0.28
["three","two","three","one","three","one","two","one","two","four"]
Output for 8.0.27
["two","three","four","two","one","two","four","three","one","three"]
Output for 8.0.26
["two","one","two","three","two","three","one","two","four","three"]
Output for 8.0.25
["two","three","four","two","one","four","one","three","one","four"]
Output for 8.0.24
["four","one","four","two","three","four","two","three","one","four"]
Output for 8.0.23
["four","one","two","one","three","two","four","one","four","one"]
Output for 8.0.22
["three","two","four","one","three","four","one","four","three","two"]
Output for 8.0.21
["one","four","three","two","four","two","one","four","one","two"]
Output for 8.0.20
["three","two","one","four","one","four","three","two","three","four"]
Output for 8.0.19
["three","one","three","one","three","four","one","four","one","three"]
Output for 8.0.18
["four","three","two","three","two","one","three","four","one","four"]
Output for 8.0.17
["four","one","three","one","two","three","two","four","three","one"]
Output for 8.0.16
["two","four","two","one","three","one","four","one","three","one"]
Output for 8.0.15
["three","two","one","two","three","four","three","four","one","three"]
Output for 8.0.14
["three","four","three","two","one","three","four","one","three","four"]
Output for 8.0.13
["three","two","three","four","two","three","four","three","one","three"]
Output for 8.0.12
["three","one","two","one","two","three","two","three","four","three"]
Output for 8.0.11
["four","one","four","three","four","one","three","two","three","four"]
Output for 8.0.10
["two","three","two","one","three","four","three","four","one","two"]
Output for 8.0.9
["one","two","three","two","four","two","three","two","four","one"]
Output for 8.0.8
["two","four","one","four","two","four","three","four","two","three"]
Output for 8.0.7
["three","four","one","four","one","four","three","two","three","two"]
Output for 8.0.6
["three","one","three","four","one","two","one","four","three","one"]
Output for 8.0.5
["three","one","three","four","one","three","four","two","one","two"]
Output for 8.0.3
["two","one","two","one","four","one","two","four","two","three"]
Output for 8.0.2
["four","two","four","two","one","two","three","two","three","two"]
Output for 8.0.1
["three","two","one","four","two","three","two","one","four","three"]

preferences:
56.29 ms | 474 KiB | 5 Q