3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_rand_cryptographically_secure(array $array): int|string { $max = count($array) - 1; if ($max < 0) { throw new ValueError ('Argument #1 ($array) cannot be empty'); } return key(array_slice($array, random_int(0, $max), 1, true)); } $tests = [ [5, 6, 7], ['a' => 1, 'b' => 2, 'c' => 3], ['zero', 4 => 'four', 9 => 'nine'] ]; foreach ($tests as $test) { echo array_rand_cryptographically_secure($test) . "\n"; }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.1.50.0180.00417.38
8.1.40.0110.00817.43
8.1.30.0120.00817.39
8.1.20.0200.00717.47
8.1.10.0200.00417.48
8.1.00.0130.00317.37
8.0.180.0120.00816.77
8.0.170.0160.00416.80
8.0.160.0170.00316.79
8.0.150.0170.00316.78
8.0.140.0130.00716.66
8.0.130.0160.00416.70
8.0.120.0160.00416.77
8.0.110.0140.00316.57
8.0.100.0160.00416.66
8.0.90.0200.00016.75
8.0.80.0160.00416.82
8.0.70.0110.01116.69
8.0.60.0190.00016.71
8.0.50.0170.00316.69
8.0.30.0140.00716.79
8.0.20.0150.00616.67
8.0.10.0180.00316.89
7.4.290.0080.00016.31
7.4.280.0180.00416.38
7.4.270.0210.00316.17
7.4.260.0200.00516.29
7.4.250.0130.00816.34
7.4.240.0160.00716.38
7.4.230.0200.00316.41
7.4.220.0100.00016.34
7.4.210.0060.00316.30
7.4.200.0180.00016.35
7.4.190.0210.00016.43
7.4.180.0160.00316.25
7.4.160.0130.00616.44
7.4.150.0070.01416.32
7.4.140.0110.00816.39
7.4.130.0100.00716.24
7.4.120.0150.00516.26
7.4.110.0160.00516.26
7.4.100.0140.00516.18
7.4.90.0130.00616.16
7.4.80.0180.00316.06
7.4.70.0160.00416.03
7.4.60.0150.00516.18
7.4.50.0220.00016.07
7.4.40.0130.00916.22
7.4.30.0120.00516.15
7.4.20.0110.00916.16
7.4.10.0140.00616.14
7.4.00.0170.00016.14

preferences:
11.95 ms | 406 KiB | 5 Q