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))); } $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.00018.68
8.3.50.0080.01022.05
8.3.40.0110.00719.10
8.3.30.0110.00418.96
8.3.20.0070.00418.98
8.3.10.0080.00020.74
8.3.00.0040.00817.88
8.2.180.0040.01118.25
8.2.170.0170.00022.96
8.2.160.0070.00722.42
8.2.150.0070.01124.18
8.2.140.0000.00824.66
8.2.130.0070.01126.16
8.2.120.0040.01120.02
8.2.110.0040.00720.66
8.2.100.0040.00817.97
8.2.90.0060.00318.09
8.2.80.0050.00317.97
8.2.70.0040.00717.88
8.2.60.0040.00718.18
8.2.50.0000.00818.16
8.2.40.0000.00818.47
8.2.30.0030.00620.01
8.2.20.0000.00817.97
8.2.10.0060.00317.94
8.2.00.0000.00817.97
8.1.280.0140.00325.92
8.1.270.0030.01023.99
8.1.260.0000.00826.35
8.1.250.0060.00328.09
8.1.240.0030.00622.30
8.1.230.0080.00421.12
8.1.220.0040.00417.91
8.1.210.0040.00419.12
8.1.200.0000.00917.47
8.1.190.0000.00817.78
8.1.180.0040.00418.10
8.1.170.0030.00519.01
8.1.160.0030.00519.04
8.1.150.0060.00318.80
8.1.140.0030.00517.69
8.1.130.0030.00318.06
8.1.120.0000.00817.77
8.1.110.0040.00417.59
8.1.100.0000.00717.71
8.1.90.0030.00617.74
8.1.80.0000.00717.70
8.1.70.0000.00717.66
8.1.60.0000.00917.84
8.1.50.0040.00417.72
8.1.40.0030.00517.75
8.1.30.0000.00717.82
8.1.20.0030.00617.91
8.1.10.0060.00317.86
8.1.00.0000.00817.74
8.0.300.0040.00420.27
8.0.290.0070.00017.13
8.0.280.0000.00718.67
8.0.270.0000.00717.49
8.0.260.0000.00718.79
8.0.250.0000.00717.09
8.0.240.0040.00417.06
8.0.230.0040.00417.19
8.0.220.0000.00716.98
8.0.210.0000.00817.11
8.0.200.0000.00817.07
8.0.190.0070.00017.20
8.0.180.0000.00817.18
8.0.170.0030.00517.09
8.0.160.0000.00717.13
8.0.150.0080.00017.02
8.0.140.0040.00417.07
8.0.130.0000.00513.56
8.0.120.0000.00817.01
8.0.110.0000.00817.03
8.0.100.0000.00717.01
8.0.90.0040.00417.10
8.0.80.0030.01217.14
8.0.70.0000.00817.00
8.0.60.0050.00317.16
8.0.50.0000.00816.97
8.0.30.0080.01017.58
8.0.20.0070.01117.51
8.0.10.0050.00317.07
8.0.00.0100.01216.96
7.4.330.0030.00314.95
7.4.320.0000.00616.74
7.4.300.0030.00316.88
7.4.290.0000.00816.88
7.4.280.0000.00716.75
7.4.270.0000.00716.76
7.4.260.0030.00313.54
7.4.250.0040.00416.79
7.4.240.0040.00416.74
7.4.230.0050.00216.91
7.4.220.0040.01516.76
7.4.210.0090.00716.82
7.4.200.0000.00816.76
7.4.190.0030.00316.99
7.4.160.0070.00716.70
7.4.150.0090.00917.40
7.4.140.0100.01317.32
7.4.130.0080.00916.69
7.4.120.0090.00816.72
7.4.110.0100.00716.65
7.4.100.0090.00916.77
7.4.90.0100.00716.72
7.4.80.0090.00919.03
7.4.70.0060.01116.65
7.4.60.0070.00916.72
7.4.50.0070.00016.48
7.4.40.0150.00322.27
7.4.30.0080.00816.73
7.4.10.0130.00715.48
7.4.00.0090.00615.08
7.3.330.0020.00213.59
7.3.320.0000.00513.34
7.3.310.0040.00216.56
7.3.300.0030.00316.47
7.3.290.0090.00616.56
7.3.280.0070.00916.59
7.3.270.0100.00717.40
7.3.260.0080.01118.24
7.3.250.0120.01016.89
7.3.240.0090.00916.50
7.3.230.0100.01016.61
7.3.210.0110.00616.53
7.3.200.0060.01319.39
7.3.190.0110.01116.74
7.3.180.0130.00316.74
7.3.170.0100.01016.87
7.3.160.0130.00916.48
7.3.130.0140.00415.49
7.3.120.0070.01015.25
7.3.110.0090.00815.28
7.3.100.0080.00515.34
7.3.90.0020.00815.15
7.3.80.0020.00915.22
7.3.70.0050.00915.24
7.3.60.0070.00715.33
7.3.50.0050.00815.21
7.3.40.0070.00515.14
7.3.30.0030.01015.13
7.3.20.0070.00817.16
7.3.10.0080.00717.02
7.3.00.0050.00617.02
7.2.330.0120.00417.07
7.2.320.0100.00717.05
7.2.310.0100.01016.58
7.2.300.0110.00716.60
7.2.290.0110.00617.01
7.2.260.0060.00815.34
7.2.250.0110.00715.34
7.2.240.0030.01115.64
7.2.230.0090.00615.47
7.2.220.0030.01115.41
7.2.210.0020.01315.54
7.2.200.0050.00915.48
7.2.190.0070.00315.49
7.2.180.0060.00615.43
7.2.170.0030.01015.39
7.2.160.0030.00815.37
7.2.150.0070.00517.11
7.2.140.0090.00417.22
7.2.130.0020.01017.21
7.2.120.0050.01017.27
7.2.110.0010.01217.23
7.2.100.0060.00717.21
7.2.90.0060.00817.15
7.2.80.0060.00717.38
7.2.70.0060.00717.27
7.2.60.0070.00817.32
7.2.50.0070.00717.31
7.2.40.0050.00617.19
7.2.30.0070.00517.28
7.2.20.0070.00717.29
7.2.10.0050.00917.28
7.2.00.0070.00717.93
7.1.330.0070.00916.28
7.1.320.0030.01016.08
7.1.310.0100.00516.28
7.1.300.0010.00816.29
7.1.290.0080.00516.12
7.1.280.0030.01316.07
7.1.270.0020.00916.19
7.1.260.0050.00616.10
7.1.250.0050.00916.14
7.1.240.0030.00616.15
7.1.230.0040.00816.13
7.1.220.0070.00716.21
7.1.210.0040.01515.96
7.1.200.0040.01015.91
7.1.190.0000.00815.88
7.1.180.0040.00415.84
7.1.170.0070.00716.24
7.1.160.0110.00416.20
7.1.150.0140.00015.98
7.1.140.0000.01315.88
7.1.130.0070.00716.14
7.1.120.0040.00416.15
7.1.110.0090.00615.92
7.1.100.0040.00917.23
7.1.90.0000.01416.29
7.1.80.0070.00716.26
7.1.70.0000.01116.80
7.1.60.0070.01217.66
7.1.50.0070.01016.70
7.1.40.0070.00316.18
7.1.30.0030.00916.08
7.1.20.0040.01115.93
7.1.10.0060.00315.88
7.1.00.0090.03719.35
7.0.330.0070.00715.70
7.0.320.0030.01015.55
7.0.310.0030.00515.78
7.0.300.0040.00415.71
7.0.290.0030.00615.78
7.0.280.0000.01115.52
7.0.270.0000.01515.79
7.0.260.0000.01115.49
7.0.250.0050.00515.90
7.0.240.0110.00315.66
7.0.230.0070.00716.09
7.0.220.0070.00715.79
7.0.210.0070.00415.57
7.0.200.0130.00716.46
7.0.190.0090.00615.89
7.0.180.0050.00315.73
7.0.170.0060.00315.88
7.0.160.0040.00715.66
7.0.150.0040.00815.74
7.0.140.0070.03718.99
7.0.130.0070.00715.88
7.0.120.0070.00715.89
7.0.110.0030.04818.06
7.0.100.0050.04718.04
7.0.90.0030.04818.17
7.0.80.0120.04017.84
7.0.70.0080.04217.84
7.0.60.0090.04218.08
7.0.50.0110.03518.07
7.0.40.0050.04516.98
7.0.30.0050.03116.92
7.0.20.0090.04516.89
7.0.10.0080.04116.88
7.0.00.0080.03316.97
5.6.400.0000.00914.84
5.6.390.0030.00914.93
5.6.380.0100.00614.30
5.6.370.0030.00714.68
5.6.360.0040.00815.00
5.6.350.0090.00614.76
5.6.340.0030.00614.80
5.6.330.0030.00514.80
5.6.320.0080.00815.02
5.6.310.0030.00614.94
5.6.300.0040.00815.01
5.6.290.0000.01214.56
5.6.280.0060.03817.98
5.6.270.0110.00314.83
5.6.260.0130.03517.94
5.6.250.0080.04417.97
5.6.240.0080.04517.80
5.6.230.0020.05017.79
5.6.220.0030.04817.86
5.6.210.0030.03317.84
5.6.200.0090.04517.97
5.6.190.0100.04017.83
5.6.180.0150.03717.76
5.6.170.0050.03417.88
5.6.160.0030.04717.82
5.6.150.0080.04317.85
5.6.140.0070.04317.77
5.6.130.0050.04717.88
5.6.120.0040.04618.00
5.6.110.0030.05017.78
5.6.100.0080.04417.74
5.6.90.0130.04017.73
5.6.80.0150.03517.60
5.6.70.0090.04317.58
5.6.60.0090.03917.51
5.6.50.0090.02517.42
5.6.40.0080.03917.38
5.6.30.0120.03917.53
5.6.20.0100.04017.61
5.6.10.0100.04117.49
5.6.00.0040.05017.54
5.5.380.0050.04217.69
5.5.370.0070.04517.74
5.5.360.0030.04517.81
5.5.350.0070.04217.78
5.5.340.0090.04317.80
5.5.330.0080.04017.79
5.5.320.0110.04117.91
5.5.310.0060.03917.72
5.5.300.0080.04217.95
5.5.290.0020.05218.05
5.5.280.0130.03518.08
5.5.270.0080.02618.00
5.5.260.0090.04017.99
5.5.250.0050.04517.84
5.5.240.0100.03517.64
5.5.230.0050.02917.40
5.5.220.0070.04417.62
5.5.210.0060.04317.49
5.5.200.0080.04117.41
5.5.190.0050.04817.50
5.5.180.0100.03717.64
5.5.170.0120.00314.58
5.5.160.0090.04017.62
5.5.150.0060.03517.52
5.5.140.0130.04017.65
5.5.130.0160.03317.57
5.5.120.0000.04717.53
5.5.110.0100.02517.76
5.5.100.0030.04517.59
5.5.90.0120.03417.40
5.5.80.0040.04117.56
5.5.70.0060.03617.48
5.5.60.0080.03217.30
5.5.50.0080.01817.40
5.5.40.0070.03517.62
5.5.30.0080.04517.38
5.5.20.0090.04017.63
5.5.10.0100.03617.33
5.5.00.0020.03217.49
5.4.450.0080.03316.30
5.4.440.0040.04916.27
5.4.430.0070.04216.29
5.4.420.0030.04416.15
5.4.410.0080.04016.12
5.4.400.0090.02516.06
5.4.390.0090.03716.01
5.4.380.0110.03316.02
5.4.370.0060.04016.02
5.4.360.0100.03516.19
5.4.350.0080.04016.11
5.4.340.0080.03815.99
5.4.330.0090.00312.79
5.4.320.0030.04016.07
5.4.310.0060.02616.07
5.4.300.0140.03616.07
5.4.290.0050.04716.03
5.4.280.0020.04715.99
5.4.270.0040.02915.99
5.4.260.0000.04316.13
5.4.250.0060.03916.13
5.4.240.0080.04016.09
5.4.230.0100.03216.10
5.4.220.0060.04315.97
5.4.210.0030.04516.03
5.4.200.0070.04216.14
5.4.190.0040.03916.01
5.4.180.0070.04316.02
5.4.170.0070.03716.17
5.4.160.0030.02816.10
5.4.150.0050.03516.02
5.4.140.0060.03714.80
5.4.130.0030.04114.74
5.4.120.0050.04214.74
5.4.110.0070.04114.70
5.4.100.0030.03314.81
5.4.90.0100.03614.83
5.4.80.0050.03814.77
5.4.70.0060.04214.81
5.4.60.0030.03814.81
5.4.50.0090.02214.71
5.4.40.0050.04214.83
5.4.30.0030.03914.80
5.4.20.0030.03614.78
5.4.10.0050.04214.78
5.4.00.0080.03814.51
5.3.290.0050.04113.87
5.3.280.0070.04113.91
5.3.270.0090.02513.84
5.3.260.0060.04213.84
5.3.250.0070.03413.91
5.3.240.0030.04913.85
5.3.230.0050.04013.81
5.3.220.0050.03713.82
5.3.210.0030.03613.93
5.3.200.0070.04013.87
5.3.190.0060.04313.80
5.3.180.0100.04013.86
5.3.170.0100.03513.89
5.3.160.0080.03813.86
5.3.150.0050.04313.83
5.3.140.0080.03813.80
5.3.130.0030.04113.81
5.3.120.0050.04213.88
5.3.110.0080.03713.81
5.3.100.0060.03713.60
5.3.90.0000.04513.53
5.3.80.0070.04013.62
5.3.70.0100.03713.58
5.3.60.0070.03813.60
5.3.50.0100.03613.45
5.3.40.0110.03513.52
5.3.30.0050.04313.51
5.3.20.0080.03713.39
5.3.10.0030.04013.37
5.3.00.0070.03513.33
5.2.170.0070.06012.08
5.2.160.0030.05312.08
5.2.150.0030.07012.08
5.2.140.0030.06712.08
5.2.130.0100.05712.08
5.2.120.0070.06012.08
5.2.110.0000.06712.08
5.2.100.0030.06012.08
5.2.90.0030.05312.08
5.2.80.0030.06712.08
5.2.70.0000.05312.08
5.2.60.0000.06312.08
5.2.50.0100.06012.08
5.2.40.0000.06312.08
5.2.30.0130.06012.08
5.2.20.0030.06312.08
5.2.10.0030.06712.08
5.2.00.0100.05712.08
5.1.60.0030.05712.08
5.1.50.0070.05712.08
5.1.40.0130.04712.08
5.1.30.0030.05312.08
5.1.20.0000.06012.08
5.1.10.0070.05312.08
5.1.00.0030.05312.08
5.0.50.0000.05012.08
5.0.40.0030.04312.08
5.0.30.0070.05712.08
5.0.20.0030.04312.08
5.0.10.0070.03712.08
5.0.00.0100.05712.08
4.4.90.0000.03712.08
4.4.80.0000.03712.08
4.4.70.0030.03312.08
4.4.60.0030.03712.08
4.4.50.0070.03312.08
4.4.40.0000.05312.08
4.4.30.0000.03312.08
4.4.20.0030.03712.08
4.4.10.0000.02012.08
4.4.00.0030.05712.08
4.3.110.0030.03712.08
4.3.100.0030.03012.08
4.3.90.0100.02012.08
4.3.80.0000.05312.08
4.3.70.0030.03312.08
4.3.60.0030.03312.08
4.3.50.0030.03712.08
4.3.40.0000.04312.08
4.3.30.0070.03012.08
4.3.20.0000.02012.08
4.3.10.0030.03712.08
4.3.00.0030.03312.08

preferences:
65.89 ms | 401 KiB | 5 Q