3v4l.org

run code in 300+ PHP versions simultaneously
<?php $list = [1, 2, 3, 4, 5, 6, 7, 8, 9]; $result = array_rand($list, 3) ; var_dump( $result ) ; ?>
Output for 8.1.9
array(3) { [0]=> int(3) [1]=> int(4) [2]=> int(6) }
Output for 8.1.8
array(3) { [0]=> int(1) [1]=> int(6) [2]=> int(8) }
Output for 7.4.8, 8.1.7
array(3) { [0]=> int(1) [1]=> int(3) [2]=> int(5) }
Output for 8.1.6
array(3) { [0]=> int(0) [1]=> int(2) [2]=> int(6) }
Output for 8.1.5
array(3) { [0]=> int(2) [1]=> int(4) [2]=> int(7) }
Output for 7.4.11, 7.4.16, 8.1.4
array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(8) }
Output for 8.1.3
array(3) { [0]=> int(2) [1]=> int(6) [2]=> int(7) }
Output for 8.1.2
array(3) { [0]=> int(3) [1]=> int(5) [2]=> int(6) }
Output for 8.1.1
array(3) { [0]=> int(3) [1]=> int(4) [2]=> int(7) }
Output for 8.0.21, 8.1.0
array(3) { [0]=> int(0) [1]=> int(6) [2]=> int(8) }
Output for 8.0.22
array(3) { [0]=> int(5) [1]=> int(6) [2]=> int(7) }
Output for 7.4.25, 8.0.20
array(3) { [0]=> int(5) [1]=> int(6) [2]=> int(8) }
Output for 8.0.1, 8.0.19
array(3) { [0]=> int(1) [1]=> int(3) [2]=> int(7) }
Output for 8.0.18
array(3) { [0]=> int(0) [1]=> int(2) [2]=> int(5) }
Output for 7.4.19, 8.0.17
array(3) { [0]=> int(0) [1]=> int(7) [2]=> int(8) }
Output for 8.0.6, 8.0.16
array(3) { [0]=> int(2) [1]=> int(5) [2]=> int(7) }
Output for 8.0.15
array(3) { [0]=> int(1) [1]=> int(3) [2]=> int(6) }
Output for 8.0.14
array(3) { [0]=> int(1) [1]=> int(6) [2]=> int(7) }
Output for 8.0.13
array(3) { [0]=> int(2) [1]=> int(3) [2]=> int(7) }
Output for 8.0.12
array(3) { [0]=> int(0) [1]=> int(3) [2]=> int(6) }
Output for 7.4.5, 8.0.3, 8.0.11
array(3) { [0]=> int(1) [1]=> int(3) [2]=> int(4) }
Output for 8.0.10
array(3) { [0]=> int(0) [1]=> int(1) [2]=> int(2) }
Output for 7.4.13, 8.0.9
array(3) { [0]=> int(2) [1]=> int(4) [2]=> int(6) }
Output for 8.0.8
array(3) { [0]=> int(0) [1]=> int(3) [2]=> int(8) }
Output for 7.4.2, 8.0.7
array(3) { [0]=> int(1) [1]=> int(5) [2]=> int(8) }
Output for 7.4.9, 7.4.21, 8.0.5
array(3) { [0]=> int(2) [1]=> int(6) [2]=> int(8) }
Output for 7.4.7, 8.0.2
array(3) { [0]=> int(2) [1]=> int(3) [2]=> int(5) }
Output for 7.4.30
array(3) { [0]=> int(2) [1]=> int(5) [2]=> int(6) }
Output for 7.4.29
array(3) { [0]=> int(1) [1]=> int(3) [2]=> int(8) }
Output for 7.4.28
array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) }
Output for 7.4.27
array(3) { [0]=> int(0) [1]=> int(1) [2]=> int(6) }
Output for 7.4.26
array(3) { [0]=> int(2) [1]=> int(3) [2]=> int(8) }
Output for 7.4.24
array(3) { [0]=> int(3) [1]=> int(4) [2]=> int(8) }
Output for 7.4.4, 7.4.23
array(3) { [0]=> int(0) [1]=> int(1) [2]=> int(8) }
Output for 7.4.22
array(3) { [0]=> int(2) [1]=> int(4) [2]=> int(5) }
Output for 7.4.20
array(3) { [0]=> int(1) [1]=> int(5) [2]=> int(6) }
Output for 7.4.18
array(3) { [0]=> int(0) [1]=> int(6) [2]=> int(7) }
Output for 7.4.15
array(3) { [0]=> int(4) [1]=> int(6) [2]=> int(8) }
Output for 7.4.3, 7.4.14
array(3) { [0]=> int(0) [1]=> int(5) [2]=> int(6) }
Output for 7.4.12
array(3) { [0]=> int(0) [1]=> int(4) [2]=> int(7) }
Output for 7.4.10
array(3) { [0]=> int(0) [1]=> int(2) [2]=> int(4) }
Output for 7.4.6
array(3) { [0]=> int(2) [1]=> int(3) [2]=> int(4) }
Output for 7.4.1
array(3) { [0]=> int(0) [1]=> int(4) [2]=> int(8) }
Output for 7.4.0
array(3) { [0]=> int(0) [1]=> int(2) [2]=> int(7) }

preferences:
29.25 ms | 470 KiB | 5 Q