3v4l.org

run code in 300+ PHP versions simultaneously
<?php // function random_number_with_dupe($len = 6, $dup = 1, $sort = false) { $num = range(0,9); shuffle($num); $num = array_slice($num, 0, ($len-$dup)+1); if ($dup > 0) { $k = array_rand($num, 1); for ($i=0;$i<($dup-1);$i++) { $num[] = $num[$k]; } } if ($sort) { sort($num); } return implode('', $num); } echo '4 unique and 2 repetitive digits.'.PHP_EOL; for ($i=0; $i<5; $i++) { echo random_number_with_dupe(6, 2, true).PHP_EOL; } /* 4 unique and 2 repetitive digits. 235699 037789 034677 012249 033569 */ echo '3 unique and 3 repetitive digits.'.PHP_EOL; for ($i=0; $i<5; $i++) { echo random_number_with_dupe(6, 3, true).PHP_EOL; } /* 3 unique and 3 repetitive digits. 015559 011147 111239 677789 456777 */ echo '2 unique and 4 repetitive digits.'.PHP_EOL; for ($i=0; $i<5; $i++) { echo random_number_with_dupe(6, 4, true).PHP_EOL; } /* 2 unique and 4 repetitive digits. 068888 022229 018888 333378 000058 */ echo '1 unique and 5 repetitive digits.'.PHP_EOL; for ($i=0; $i<5; $i++) { echo random_number_with_dupe(6, 5, true).PHP_EOL; } /* 1 unique and 5 repetitive digits. 788888 066666 799999 355555 244444 */ echo '0 unique and 6 repetitive digits.'.PHP_EOL; for ($i=0; $i<5; $i++) { echo random_number_with_dupe(6, 6, true).PHP_EOL; } /* 0 unique and 6 repetitive digits. 888888 333333 777777 888888 777777 */ echo 'All rules.'.PHP_EOL; for ($i=0; $i<6; $i++) { echo random_number_with_dupe(6, $i+1, true).PHP_EOL; } /* All rules. 345789 003569 245666 000089 777778 555555 */ echo 'All rules (random).'.PHP_EOL; for ($i=0; $i<6; $i++) { echo random_number_with_dupe(6, mt_rand(1, 6), true).PHP_EOL; } /* All rules (random). 225678 222222 111359 444444 777778 233349 */

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)
7.3.10.0130.00016.33
7.3.00.0090.00616.23
7.2.130.0090.00616.89
7.2.120.0160.00916.29
7.2.110.0160.01016.60
7.2.100.0070.01116.51
7.2.90.0120.00616.66
7.2.80.0040.01516.41
7.2.70.0070.00716.61
7.2.60.0060.00917.05
7.2.50.0070.00716.49
7.2.40.0160.00316.30
7.2.30.0110.00716.64
7.2.20.0060.01216.71
7.2.10.0130.01316.66
7.2.00.0100.00917.09
7.1.250.0070.01515.39
7.1.120.0030.01217.17
7.1.110.0060.01616.57
7.1.100.0110.00916.21
7.1.90.0150.01216.40
7.1.80.0140.01416.18
7.1.70.0080.01615.41
7.1.60.0350.00933.33
7.1.50.0280.02132.96
7.1.40.0260.01332.57
7.1.30.0240.02132.78
7.1.20.0250.01832.93
7.1.10.0030.01614.59
7.1.00.0090.01414.94
7.0.260.0120.01216.71
7.0.250.0150.00616.08
7.0.240.0100.00616.22
7.0.230.0100.01015.71
7.0.220.0060.01215.75
7.0.210.0640.01214.89
7.0.200.0130.01215.13
7.0.190.0110.00714.86
7.0.180.0030.01714.57
7.0.170.0060.01914.47
7.0.160.0080.01614.57
7.0.150.0040.01114.57
7.0.140.0120.00414.52
7.0.130.0070.01014.69
7.0.120.0270.01414.54
7.0.110.0160.00714.62
7.0.100.0110.01114.51
7.0.90.0070.00714.48
7.0.80.0060.01314.54
7.0.70.0090.00614.74
7.0.60.0070.01314.52
7.0.50.0060.01614.65
7.0.40.0000.01814.77
7.0.30.0090.01314.94
7.0.20.0180.00014.54
7.0.10.0060.01814.79
7.0.00.0030.02014.59

preferences:
27.25 ms | 403 KiB | 5 Q