3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_rand_cryptographically_secure(array $array): int|string { if (!$array) { throw new ValueError ('Argument #1 ($array) cannot be empty'); } return key(array_slice($array, random_int(0, count($array) - 1), 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.0210.00617.32
8.1.40.0070.01117.48
8.1.30.0150.00617.44
8.1.20.0180.00617.45
8.1.10.0170.00817.42
8.1.00.0140.00617.33
8.0.180.0150.00816.70
8.0.170.0100.01016.71
8.0.160.0190.00016.75
8.0.150.0170.00416.86
8.0.140.0160.00316.75
8.0.130.0160.00416.80
8.0.120.0170.00416.75
8.0.110.0140.00416.67
8.0.100.0220.00016.82
8.0.90.0130.01016.71
8.0.80.0170.00616.90
8.0.70.0180.00616.71
8.0.60.0160.00316.63
8.0.50.0120.00816.86
8.0.30.0140.00716.65
8.0.20.0110.01116.79
8.0.10.0190.00316.91
7.4.290.0020.00616.32
7.4.280.0200.00316.30
7.4.270.0250.00016.40
7.4.260.0240.00016.30
7.4.250.0180.00416.37
7.4.240.0210.00016.15
7.4.230.0130.00716.39
7.4.220.0170.00316.38
7.4.210.0100.00316.36
7.4.200.0140.00416.27
7.4.190.0210.00316.44
7.4.180.0160.00216.41
7.4.160.0200.00316.23
7.4.150.0050.01416.20
7.4.140.0110.00716.25
7.4.130.0140.00416.02
7.4.120.0150.00516.20
7.4.110.0170.00316.16
7.4.100.0100.01016.21
7.4.90.0150.00516.29
7.4.80.0120.00816.21
7.4.70.0120.00816.03
7.4.60.0140.00516.19
7.4.50.0140.00516.11
7.4.40.0000.00816.02
7.4.30.0060.00316.20
7.4.20.0040.00416.19
7.4.10.0100.00316.09
7.4.00.0090.00316.24

preferences:
36.2 ms | 401 KiB | 5 Q