3v4l.org

run code in 300+ PHP versions simultaneously
<?php $number = 1000000; $hyphen = '-'; $conjunction = ' and '; $separator = ', '; $negative = 'negative '; $decimal = ' point '; $dictionary = array( 0 => 'zero', 1 => 'one', 2 => 'two', 3 => 'three', 4 => 'four', 5 => 'five', 6 => 'six', 7 => 'seven', 8 => 'eight', 9 => 'nine', 10 => 'ten', 11 => 'eleven', 12 => 'twelve', 13 => 'thirteen', 14 => 'fourteen', 15 => 'fifteen', 16 => 'sixteen', 17 => 'seventeen', 18 => 'eighteen', 19 => 'nineteen', 20 => 'twenty', 30 => 'thirty', 40 => 'fourty', 50 => 'fifty', 60 => 'sixty', 70 => 'seventy', 80 => 'eighty', 90 => 'ninety', 100 => 'hundred', 1000 => 'thousand', 100000 => 'lakhs', 10000000 => 'cores', 1000000000 => 'billion', 1000000000000 => 'trillion', 1000000000000000 => 'quadrillion', 1000000000000000000 => 'quintillion' ); if (!is_numeric($number)) { return false; } if (($number >= 0 && (int) $number < 0) || (int) $number < 0 - PHP_INT_MAX) { // overflow trigger_error( 'convert_number_to_words only accepts numbers between -' . PHP_INT_MAX . ' and ' . PHP_INT_MAX, E_USER_WARNING ); return false; } if ($number < 0) { return $negative . convert_number_to_words(abs($number)); } $string = $fraction = null; if (strpos($number, '.') !== false) { list($number, $fraction) = explode('.', $number); } switch (true) { case $number < 21: $string = $dictionary[$number]; break; case $number < 100: $tens = ((int) ($number / 10)) * 10; $units = $number % 10; $string = $dictionary[$tens]; if ($units) { $string .= $hyphen . $dictionary[$units]; } break; case $number < 1000: $hundreds = $number / 100; $remainder = $number % 100; $string = $dictionary[$hundreds] . ' ' . $dictionary[100]; if ($remainder) { $string .= $conjunction . convert_number_to_words($remainder); } break; default: $pow = floor(log($number, 10)); $remainer_val = 100; if($pow > 3 && $pow < 6 ) { $baseUnit = pow(1000, floor(log($number, 1000))); } else if($pow > 5 && $pow < 8 ) { $baseUnit = 100000; $remainer_val = 10; } else if($pow > 7 && $pow < 10 ) { $baseUnit = 10000000; $remainer_val = 10; } else { $baseUnit = pow(1000, floor(log($number, 1000))); } $numBaseUnits = (int) ($number / $baseUnit); $remainder = $number % $baseUnit; $string = convert_number_to_words($numBaseUnits) . ' ' . $dictionary[$baseUnit]; if ($remainder) { $string .= $remainder < $remainer_val ? $conjunction : $separator; $string .= convert_number_to_words($remainder); } break; } if (null !== $fraction && is_numeric($fraction)) { $string .= $decimal; $words = array(); foreach (str_split((string) $fraction) as $number) { $words[] = $dictionary[$number]; } $string .= implode(' ', $words); } echo $string;

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.3.60.0150.00016.98
8.3.50.0120.00517.68
8.3.40.0120.00319.08
8.3.30.0160.00018.68
8.3.20.0090.00619.15
8.3.10.0090.00020.91
8.3.00.0060.00319.63
8.2.180.0140.00717.13
8.2.170.0070.01322.96
8.2.160.0150.00022.38
8.2.150.0000.00824.18
8.2.140.0080.00024.66
8.2.130.0040.00426.16
8.2.120.0060.00318.25
8.2.110.0090.00622.28
8.2.100.0110.00017.97
8.2.90.0080.00417.75
8.2.80.0080.00018.29
8.2.70.0000.00818.18
8.2.60.0000.00818.34
8.2.50.0040.00418.10
8.2.40.0040.00419.60
8.2.30.0000.00718.43
8.2.20.0040.00417.95
8.2.10.0060.00318.05
8.2.00.0040.00418.02
8.1.280.0080.00825.92
8.1.270.0040.00423.99
8.1.260.0080.00026.35
8.1.250.0080.00028.09
8.1.240.0120.00924.13
8.1.230.0040.00719.21
8.1.220.0050.00317.79
8.1.210.0060.00318.77
8.1.200.0060.00317.48
8.1.190.0000.00917.60
8.1.180.0000.00818.10
8.1.170.0090.00018.74
8.1.160.0040.00419.15
8.1.150.0000.00818.91
8.1.140.0000.00717.68
8.1.130.0030.00318.13
8.1.120.0040.00417.77
8.1.110.0060.00317.71
8.1.100.0030.00617.68
8.1.90.0040.00417.69
8.1.80.0040.00417.67
8.1.70.0080.00017.58
8.1.60.0080.00017.71
8.1.50.0000.00717.67
8.1.40.0030.00517.78
8.1.30.0040.00417.87
8.1.20.0000.00817.89
8.1.10.0000.00917.70
8.1.00.0000.00817.68
8.0.300.0040.00420.02
8.0.290.0030.00717.00
8.0.280.0000.00718.78
8.0.270.0040.00417.54
8.0.260.0030.00317.11
8.0.250.0070.00317.25
8.0.240.0080.00317.27
8.0.230.0000.00817.27
8.0.220.0030.00317.19
8.0.210.0030.00517.07
8.0.200.0030.00317.09
8.0.190.0000.00817.09
8.0.180.0050.00317.21
8.0.170.0080.00017.14
8.0.160.0000.00817.07
8.0.150.0070.00017.23
8.0.140.0000.00817.10
8.0.130.0050.00313.59
8.0.120.0000.00817.13
8.0.110.0000.00717.02
8.0.100.0080.00017.18
8.0.90.0030.00517.05
8.0.80.0080.00817.07
8.0.70.0080.00017.20
8.0.60.0000.00817.05
8.0.50.0040.00417.13
8.0.30.0040.01517.23
8.0.20.0120.00717.45
8.0.10.0000.00717.33
8.0.00.0140.00717.10
7.4.330.0020.00213.10
7.4.320.0000.00616.87
7.4.300.0000.00616.59
7.4.290.0000.00716.73
7.4.280.0050.00516.63
7.4.270.0030.00316.73
7.4.260.0030.00313.57
7.4.250.0030.00516.77
7.4.240.0040.00416.86
7.4.230.0030.00516.85
7.4.220.0070.01416.77
7.4.210.0060.00916.73
7.4.200.0040.00416.77
7.4.190.0030.00316.60
7.4.160.0120.00316.63
7.4.150.0090.00916.83
7.4.140.0070.01016.79
7.4.130.0100.01016.78
7.4.120.0090.01116.72
7.4.110.0100.00716.65
7.4.100.0090.00916.66
7.4.90.0130.01016.79
7.4.80.0070.01116.80
7.4.70.0060.01216.65
7.4.60.0120.00416.64
7.4.50.0060.00316.84
7.4.40.0080.00616.62
7.4.30.0120.00316.98
7.4.00.0080.00815.36
7.3.330.0000.00713.50
7.3.320.0030.00313.52
7.3.310.0070.00016.59
7.3.300.0000.00616.48
7.3.290.0060.00916.65
7.3.280.0080.00716.65
7.3.270.0140.00416.78
7.3.260.0100.00916.75
7.3.250.0170.00316.70
7.3.240.0100.01316.65
7.3.230.0130.00616.56
7.3.210.0090.01016.58
7.3.200.0110.01119.39
7.3.190.0160.00616.68
7.3.180.0160.00416.77
7.3.170.0170.00016.77
7.3.160.0050.01316.64
7.3.120.0090.00015.34
7.2.330.0100.00716.95
7.2.320.0030.01916.85
7.2.310.0070.01916.94
7.2.300.0120.00616.66
7.2.290.0070.01016.76
7.2.60.0070.00717.32
7.2.00.0060.00919.72
7.1.200.0070.00716.09
7.1.100.0100.00318.46
7.1.70.0060.00617.51
7.1.60.0070.02019.40
7.1.50.0100.01017.32
7.1.00.0000.07722.81
7.0.200.0030.00317.04
7.0.140.0070.07022.23
7.0.60.0130.08020.29
7.0.50.0100.08018.32
7.0.40.0100.07018.01
7.0.30.0130.07718.03
7.0.20.0030.07718.00
7.0.10.0100.09018.01
7.0.00.0100.08317.94
5.6.280.0070.07021.45
5.6.210.0200.07020.88
5.6.200.0070.07018.50
5.6.190.0100.08018.52
5.6.180.0070.08718.43
5.6.170.0070.05718.39
5.6.160.0030.08318.37
5.6.150.0100.07318.51
5.6.140.0070.07318.46
5.6.130.0070.05318.50
5.6.120.0100.05318.36
5.6.110.0100.04318.36
5.6.100.0100.07718.50
5.6.90.0130.06018.47
5.6.80.0100.07017.88
5.6.70.0130.03717.88
5.6.60.0100.07017.90
5.6.50.0070.06717.78
5.6.40.0170.06717.76
5.6.30.0100.07017.79
5.6.20.0030.06717.75
5.6.10.0030.05317.79
5.6.00.0100.06017.84
5.5.350.0370.07320.78
5.5.340.0030.05318.27
5.5.330.0100.07318.18
5.5.320.0070.08318.21
5.5.310.0100.07318.16
5.5.300.0100.07718.29
5.5.290.0030.08318.29
5.5.280.0030.08318.26
5.5.270.0130.07318.16
5.5.260.0170.07718.25
5.5.250.0070.04718.08
5.5.240.0070.06317.52
5.5.230.0130.06317.59
5.5.220.0100.06717.59
5.5.210.0030.08317.64
5.5.200.0070.07717.64
5.5.190.0000.08017.62
5.5.180.0070.07717.60
5.5.160.0030.07717.48
5.5.150.0100.07317.63
5.5.140.0130.07017.55
5.5.130.0030.07017.61
5.5.120.0100.03317.50
5.5.110.0070.03717.60
5.5.100.0130.05717.41
5.5.90.0070.04017.42
5.5.80.0030.04317.52
5.5.70.0030.05017.40
5.5.60.0070.07317.45
5.5.50.0100.07317.40
5.5.40.0070.04017.47
5.5.30.0030.08017.41
5.5.20.0100.07317.41
5.5.10.0100.03717.43
5.5.00.0070.04717.51
5.4.450.0100.07319.59
5.4.440.0070.05019.63
5.4.430.0070.04719.61
5.4.420.0070.08319.58
5.4.410.0100.04719.40
5.4.400.0100.07319.27
5.4.390.0100.04019.14
5.4.380.0030.07719.23
5.4.370.0100.07719.32
5.4.360.0130.06319.29
5.4.350.0030.09319.37
5.4.340.0270.05719.20
5.4.320.0070.07719.23
5.4.310.0130.07319.23
5.4.300.0030.08319.07
5.4.290.0000.08319.26
5.4.280.0070.05719.36
5.4.270.0170.02719.39
5.4.260.0000.05019.23
5.4.250.0170.06719.36
5.4.240.0030.04019.27
5.4.230.0100.07719.20
5.4.220.0070.05319.36
5.4.210.0130.04319.30
5.4.200.0070.07019.07
5.4.190.0100.06719.23
5.4.180.0130.06319.25
5.4.170.0070.03719.24
5.4.160.0030.04019.35
5.4.150.0000.04319.26
5.4.140.0070.07316.63
5.4.130.0030.04716.62
5.4.120.0000.04016.69
5.4.110.0170.06316.61
5.4.100.0030.07016.57
5.4.90.0100.04016.75
5.4.80.0100.07316.82
5.4.70.0070.07316.54
5.4.60.0070.05716.57
5.4.50.0100.07016.59
5.4.40.0100.06716.48
5.4.30.0130.06716.58
5.4.20.0100.06316.54
5.4.10.0000.04016.58
5.4.00.0030.04316.04
5.3.290.0130.07014.75
5.3.280.0070.04714.71
5.3.270.0030.04014.85
5.3.260.0000.04314.85
5.3.250.0070.04314.85
5.3.240.0100.06714.86
5.3.230.0000.05014.76
5.3.220.0130.05314.93
5.3.210.0070.06714.78
5.3.200.0070.07314.80
5.3.190.0030.07314.76
5.3.180.0070.08014.77
5.3.170.0100.06714.73
5.3.160.0030.04014.79
5.3.150.0030.04714.79
5.3.140.0070.04014.72
5.3.130.0070.06314.77
5.3.120.0100.07014.76
5.3.110.0130.04314.79
5.3.100.0070.07714.40
5.3.90.0100.07014.24
5.3.80.0000.05014.26
5.3.70.0000.08314.21
5.3.60.0030.08014.27
5.3.50.0000.04714.20
5.3.40.0070.07714.19
5.3.30.0200.02714.11
5.3.20.0170.07013.89
5.3.10.0070.07013.92
5.3.00.0130.03013.83
5.2.170.0070.03311.42
5.2.160.0030.03011.27
5.2.150.0030.06711.40
5.2.140.0100.05311.21
5.2.130.0030.06311.27
5.2.120.0100.05011.37
5.2.110.0030.05311.36
5.2.100.0100.03711.36
5.2.90.0000.03711.38
5.2.80.0000.03711.31
5.2.70.0030.04711.38
5.2.60.0070.06011.32
5.2.50.0000.05311.31
5.2.40.0030.06011.26
5.2.30.0100.05711.19
5.2.20.0070.04711.22
5.2.10.0070.05711.20
5.2.00.0030.04711.04
5.1.60.0030.06010.32
5.1.50.0030.06010.33
5.1.40.0000.04010.24
5.1.30.0070.05010.47
5.1.20.0000.06710.70
5.1.10.0000.05010.44
5.1.00.0100.04010.39
5.0.50.0030.0508.94
5.0.40.0000.0478.75
5.0.30.0000.0478.56
5.0.20.0000.0278.52
5.0.10.0030.0438.45
5.0.00.0070.0508.50
4.4.90.0000.0277.75
4.4.80.0030.0337.75
4.4.70.0000.0337.75
4.4.60.0100.0307.75
4.4.50.0070.0177.75
4.4.40.0000.0577.75
4.4.30.0030.0377.75
4.4.20.0000.0407.75
4.4.10.0070.0277.75
4.4.00.0030.0577.75
4.3.110.0070.0337.75
4.3.100.0000.0237.75
4.3.90.0030.0337.75
4.3.80.0000.0477.75
4.3.70.0070.0307.75
4.3.60.0030.0307.75
4.3.50.0030.0337.75
4.3.40.0030.0337.75
4.3.30.0030.0237.75
4.3.20.0000.0277.75
4.3.10.0030.0207.75
4.3.00.0030.0307.75

preferences:
40.81 ms | 401 KiB | 5 Q