3v4l.org

run code in 300+ PHP versions simultaneously
<?php $number = 1000000; echo convert_number_to_words($number); function convert_number_to_words($number) { $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))); } echo $pow; echo $baseUnit; $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.0140.00416.88
8.3.50.0060.00917.45
8.3.40.0120.00318.98
8.3.30.0090.00618.92
8.3.20.0050.00318.98
8.3.10.0080.00020.66
8.3.00.0060.00319.51
8.2.180.0140.00716.88
8.2.170.0100.00322.96
8.2.160.0070.00721.44
8.2.150.0030.00624.18
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0030.00619.61
8.2.110.0070.00322.52
8.2.100.0080.00418.09
8.2.90.0040.00419.42
8.2.80.0050.00317.97
8.2.70.0080.00017.88
8.2.60.0030.00618.18
8.2.50.0000.00918.07
8.2.40.0040.00418.30
8.2.30.0070.00318.33
8.2.20.0040.00417.96
8.2.10.0000.00818.05
8.2.00.0040.00417.85
8.1.280.0070.00725.92
8.1.270.0000.00724.66
8.1.260.0080.00026.35
8.1.250.0040.00428.09
8.1.240.0000.00922.37
8.1.230.0090.00317.66
8.1.220.0040.00417.90
8.1.210.0030.00518.77
8.1.200.0090.00317.60
8.1.190.0030.00517.77
8.1.180.0050.00318.10
8.1.170.0040.00419.21
8.1.160.0040.00419.17
8.1.150.0000.00818.88
8.1.140.0030.00517.61
8.1.130.0000.00718.13
8.1.120.0000.00817.70
8.1.110.0000.00717.67
8.1.100.0000.00717.62
8.1.90.0040.00417.75
8.1.80.0030.00617.64
8.1.70.0030.00517.67
8.1.60.0080.00017.70
8.1.50.0040.00417.69
8.1.40.0030.00517.75
8.1.30.0000.00717.91
8.1.20.0050.00317.91
8.1.10.0000.00817.72
8.1.00.0030.00517.70
8.0.300.0060.00318.77
8.0.290.0000.00817.00
8.0.280.0040.00418.64
8.0.270.0000.00717.61
8.0.260.0030.00316.97
8.0.250.0050.00217.25
8.0.240.0080.00017.04
8.0.230.0000.00717.07
8.0.220.0040.00417.07
8.0.210.0040.00417.04
8.0.200.0030.00317.17
8.0.190.0040.00417.19
8.0.180.0030.00517.16
8.0.170.0030.00617.16
8.0.160.0000.00817.05
8.0.150.0080.00017.12
8.0.140.0000.00816.98
8.0.130.0000.00613.55
8.0.120.0030.00717.09
8.0.110.0040.00417.25
8.0.100.0040.00417.02
8.0.90.0050.00217.01
8.0.80.0100.00717.14
8.0.70.0000.00717.20
8.0.60.0000.00717.05
8.0.50.0000.00717.16
8.0.30.0100.01217.04
8.0.20.0080.01017.32
8.0.10.0070.00017.23
8.0.00.0100.00917.02
7.4.330.0050.00013.22
7.4.320.0040.00416.68
7.4.300.0000.00716.83
7.4.290.0030.00516.57
7.4.280.0000.00716.71
7.4.270.0000.00716.80
7.4.260.0030.00313.51
7.4.250.0030.00616.73
7.4.240.0000.00716.89
7.4.230.0030.00316.70
7.4.220.0100.01716.87
7.4.210.0070.00716.77
7.4.200.0030.00316.91
7.4.190.0030.00316.71
7.4.160.0050.01116.68
7.4.150.0070.01116.67
7.4.140.0000.01816.62
7.4.130.0070.01016.69
7.4.120.0090.00816.76
7.4.110.0070.01016.62
7.4.100.0120.00616.82
7.4.90.0150.01316.79
7.4.80.0120.00816.64
7.4.70.0070.01016.66
7.4.60.0090.00916.72
7.4.50.0050.00316.79
7.4.40.0030.00716.66
7.4.30.0030.01216.64
7.4.00.0030.01015.32
7.3.330.0000.00613.37
7.3.320.0000.00513.53
7.3.310.0040.00416.50
7.3.300.0070.00016.59
7.3.290.0130.00416.57
7.3.280.0110.00816.61
7.3.270.0070.01016.56
7.3.260.0120.00616.88
7.3.250.0080.01416.73
7.3.240.0090.00916.64
7.3.230.0130.00316.98
7.3.210.0060.01216.54
7.3.200.0060.01319.39
7.3.190.0100.01016.84
7.3.180.0090.00816.88
7.3.170.0100.01016.88
7.3.160.0000.01616.69
7.3.120.0070.00715.24
7.3.00.0040.01116.90
7.2.330.0150.00316.68
7.2.320.0130.00316.88
7.2.310.0090.01517.14
7.2.300.0100.01417.06
7.2.290.0120.00616.68
7.2.130.0070.01017.33
7.2.120.0040.01117.19
7.2.110.0070.00717.39
7.2.100.0060.00917.42
7.2.90.0040.01417.00
7.2.80.0060.00917.21
7.2.70.0060.00817.36
7.2.60.0060.00817.07
7.2.50.0060.00817.21
7.2.40.0030.01217.30
7.2.30.0100.00317.08
7.2.20.0060.00616.86
7.2.10.0060.00817.37
7.2.00.0050.00718.66
7.1.250.0080.00616.16
7.1.240.0100.00016.09
7.1.230.0000.01415.91
7.1.220.0070.01016.18
7.1.210.0100.00716.22
7.1.200.0070.00216.12
7.1.190.0100.00316.25
7.1.180.0140.00016.11
7.1.170.0060.00616.13
7.1.160.0100.00615.95
7.1.150.0070.00716.03
7.1.140.0060.00616.01
7.1.130.0040.01116.19
7.1.120.0000.01216.24
7.1.110.0040.00715.96
7.1.100.0100.00417.21
7.1.90.0000.01416.36
7.1.80.0030.00916.26
7.1.70.0040.00716.64
7.1.60.0050.01617.76
7.1.50.0050.01316.65
7.1.40.0060.00616.47
7.1.30.0030.00916.34
7.1.20.0030.01316.26
7.1.10.0060.00715.96
7.1.00.0020.04019.36
7.0.330.0110.00015.67
7.0.320.0070.00415.69
7.0.310.0060.00615.54
7.0.300.0070.00715.97
7.0.290.0150.00015.77
7.0.280.0090.00315.38
7.0.270.0000.01515.85
7.0.260.0000.01015.71
7.0.250.0040.00815.68
7.0.240.0000.01515.58
7.0.230.0030.00615.65
7.0.220.0040.01115.62
7.0.210.0000.00915.68
7.0.200.0150.00515.49
7.0.190.0070.00415.72
7.0.180.0100.00315.57
7.0.170.0060.00315.77
7.0.160.0030.01015.84
7.0.150.0000.01315.68
7.0.140.0050.03918.92
7.0.130.0080.00015.73
7.0.120.0050.04119.07
7.0.110.0050.00815.79
7.0.100.0070.00715.68
7.0.90.0140.00015.70
7.0.80.0040.01115.79
7.0.70.0060.00315.39
7.0.60.0030.05218.04
7.0.50.0070.02217.00
7.0.40.0050.02515.88
7.0.30.0090.02015.92
7.0.20.0080.02015.85
7.0.10.0020.02815.72
7.0.00.0050.02215.90
5.6.380.0030.01314.93
5.6.370.0090.00014.64
5.6.360.0090.00614.89
5.6.350.0030.00914.57
5.6.340.0040.01114.80
5.6.330.0000.01414.87
5.6.320.0080.00614.91
5.6.310.0070.00714.80
5.6.300.0040.00414.54
5.6.290.0070.00714.80
5.6.280.0050.04018.04
5.6.270.0110.00314.79
5.6.260.0080.00814.55
5.6.250.0100.00014.73
5.6.240.0060.00314.79
5.6.230.0030.01114.89
5.6.220.0000.01214.48
5.6.210.0050.02517.82
5.6.200.0070.02316.68
5.6.190.0030.02516.59
5.6.180.0030.02416.73
5.6.170.0050.02516.61
5.6.160.0070.02016.55
5.6.150.0070.02316.59
5.6.140.0050.02316.61
5.6.130.0020.02716.69
5.6.120.0080.02216.63
5.6.110.0070.02016.61
5.6.100.0040.02216.61
5.6.90.0030.02716.74
5.6.80.0030.02516.42
5.6.70.0050.02016.24
5.6.60.0030.02516.31
5.6.50.0060.03816.33
5.6.40.0030.02616.30
5.6.30.0050.02516.23
5.6.20.0060.04316.36
5.6.10.0070.03216.32
5.6.00.0090.02516.42
5.5.380.0030.00711.77
5.5.370.0060.00311.53
5.5.360.0100.00011.39
5.5.350.0130.02516.11
5.5.340.0020.02714.71
5.5.330.0010.02314.93
5.5.320.0070.02014.92
5.5.310.0050.02015.04
5.5.300.0070.02214.89
5.5.290.0070.01914.87
5.5.280.0030.02514.97
5.5.270.0050.02014.93
5.5.260.0050.02114.85
5.5.250.0030.02314.84
5.5.240.0020.02914.50
5.5.230.0030.02314.54
5.5.220.0030.02014.57
5.5.210.0060.02614.39
5.5.200.0070.04214.46
5.5.190.0050.02514.52
5.5.180.0080.04214.47
5.5.170.0060.00611.37
5.5.160.0100.03714.44
5.5.150.0070.03414.54
5.5.140.0060.02414.36
5.5.130.0060.02614.64
5.5.120.0050.04214.73
5.5.110.0100.02814.60
5.5.100.0080.03814.56
5.5.90.0090.02114.52
5.5.80.0050.03414.56
5.5.70.0070.02514.44
5.5.60.0070.03614.55
5.5.50.0070.02314.42
5.5.40.0100.03314.55
5.5.30.0070.03714.41
5.5.20.0030.03014.46
5.5.10.0050.03614.46
5.5.00.0070.03314.29
5.4.450.0050.02315.56
5.4.440.0050.02315.54
5.4.430.0030.02315.45
5.4.420.0030.02215.47
5.4.410.0030.02215.46
5.4.400.0050.02215.41
5.4.390.0050.02115.16
5.4.380.0050.02015.28
5.4.370.0020.02515.45
5.4.360.0030.03015.39
5.4.350.0050.02315.37
5.4.340.0050.02215.21
5.4.330.0030.00911.49
5.4.320.0050.03915.36
5.4.310.0080.02515.17
5.4.300.0100.03515.38
5.4.290.0130.02815.39
5.4.280.0070.03615.40
5.4.270.0030.02915.33
5.4.260.0080.04015.36
5.4.250.0070.02915.42
5.4.240.0060.04115.35
5.4.230.0070.03415.35
5.4.220.0130.02515.24
5.4.210.0080.03615.20
5.4.200.0170.03015.35
5.4.190.0030.02715.34
5.4.180.0060.04015.31
5.4.170.0030.02415.38
5.4.160.0050.04515.23
5.4.150.0100.03815.45
5.4.140.0070.03114.05
5.4.130.0050.03313.88
5.4.120.0080.03514.02
5.4.110.0020.02214.04
5.4.100.0070.01913.98
5.4.90.0080.01813.92
5.4.80.0030.04013.99
5.4.70.0050.03713.89
5.4.60.0120.03214.00
5.4.50.0100.03313.87
5.4.40.0020.04314.08
5.4.30.0100.02813.92
5.4.20.0020.02613.88
5.4.10.0060.03914.12
5.4.00.0040.02213.64
5.3.290.0060.02312.96
5.3.280.0050.02712.97
5.3.270.0120.02712.96
5.3.260.0080.03513.05
5.3.250.0050.02713.00
5.3.240.0070.03712.96
5.3.230.0120.01812.98
5.3.220.0080.03912.95
5.3.210.0050.02512.94
5.3.200.0070.03412.91
5.3.190.0030.02312.94
5.3.180.0050.02112.97
5.3.170.0080.02412.98
5.3.160.0050.04212.98
5.3.150.0030.04812.95
5.3.140.0060.04212.95
5.3.130.0070.04012.95
5.3.120.0120.02912.97
5.3.110.0050.03512.95
5.3.100.0050.02212.71
5.3.90.0080.02412.65
5.3.80.0030.04212.75
5.3.70.0100.03012.69
5.3.60.0060.03512.60
5.3.50.0100.03312.65
5.3.40.0080.03912.64
5.3.30.0050.03812.64
5.3.20.0050.04112.49
5.3.10.0040.02612.47
5.3.00.0080.03312.49
5.2.170.0050.03311.24
5.2.160.0050.03011.22
5.2.150.0100.02811.23
5.2.140.0050.01911.21
5.2.130.0050.02311.21
5.2.120.0050.01911.15
5.2.110.0060.03311.23
5.2.100.0070.02511.23
5.2.90.0020.02911.17
5.2.80.0050.03311.20
5.2.70.0040.02111.21
5.2.60.0050.02811.20
5.2.50.0020.02011.18
5.2.40.0060.01211.15
5.2.30.0000.02211.13
5.2.20.0020.02111.11
5.2.10.0070.03211.11
5.2.00.0070.03211.11
5.1.60.0050.02111.11
5.1.50.0030.02811.11
5.1.40.0080.02311.11
5.1.30.0050.02711.11
5.1.20.0090.01711.11
5.1.10.0020.03211.11
5.1.00.0000.02311.11
5.0.50.0050.01711.11
5.0.40.0020.01211.11
5.0.30.0030.03111.11
5.0.20.0010.02311.11
5.0.10.0030.01811.11
5.0.00.0030.03011.11
4.4.90.0020.02211.11
4.4.80.0000.01711.11
4.4.70.0050.01711.11
4.4.60.0010.01911.11
4.4.50.0030.01711.11
4.4.40.0000.01811.11
4.4.30.0030.02011.11
4.4.20.0000.02411.11
4.4.10.0020.02111.11
4.4.00.0010.02811.11
4.3.110.0020.02011.11
4.3.100.0030.02111.11
4.3.90.0020.01911.11
4.3.80.0030.02711.11
4.3.70.0020.01911.11
4.3.60.0030.02011.11
4.3.50.0020.02011.11
4.3.40.0020.02911.11
4.3.30.0020.01011.11
4.3.20.0030.00811.11
4.3.10.0050.01811.11
4.3.00.0030.01811.11

preferences:
43.21 ms | 401 KiB | 5 Q