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 < 5 ) { $baseUnit = pow(1000, floor(log($number, 1000))); } else if($pow >= 5 && $pow < 7 ) { $baseUnit = 100000; $remainer_val = 10; } else if($pow >= 7 && $pow < 9 ) { $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.0070.01317.00
8.3.50.0120.00522.06
8.3.40.0090.00619.10
8.3.30.0130.00319.34
8.3.20.0040.00420.59
8.3.10.0050.00223.73
8.3.00.0000.00919.44
8.2.180.0160.00016.75
8.2.170.0070.00722.96
8.2.160.0070.00720.51
8.2.150.0030.00524.18
8.2.140.0040.00424.66
8.2.130.0070.00026.16
8.2.120.0090.00020.95
8.2.110.0000.01121.21
8.2.100.0120.00018.16
8.2.90.0030.00619.48
8.2.80.0000.00817.97
8.2.70.0000.00817.88
8.2.60.0050.00318.05
8.2.50.0040.00418.10
8.2.40.0000.00920.90
8.2.30.0050.00218.51
8.2.20.0000.00717.98
8.2.10.0070.00018.43
8.2.00.0000.00817.88
8.1.280.0090.00625.92
8.1.270.0000.00923.96
8.1.260.0050.00326.35
8.1.250.0000.00828.09
8.1.240.0050.00522.93
8.1.230.0000.01118.02
8.1.220.0030.00517.91
8.1.210.0040.00418.77
8.1.200.0060.00317.48
8.1.190.0000.00817.38
8.1.180.0040.00418.10
8.1.170.0040.00418.84
8.1.160.0040.00422.39
8.1.150.0050.00318.82
8.1.140.0040.00417.65
8.1.130.0000.00717.94
8.1.120.0000.00717.75
8.1.110.0020.00517.71
8.1.100.0070.00017.55
8.1.90.0000.00717.66
8.1.80.0080.00017.56
8.1.70.0030.00317.63
8.1.60.0050.00517.87
8.1.50.0060.00317.75
8.1.40.0100.00017.65
8.1.30.0040.00417.84
8.1.20.0000.00917.86
8.1.10.0040.00417.69
8.1.00.0000.00717.77
8.0.300.0060.00318.77
8.0.290.0040.00417.00
8.0.280.0030.00318.68
8.0.270.0000.00717.45
8.0.260.0000.00617.54
8.0.250.0050.00317.07
8.0.240.0000.00817.19
8.0.230.0070.00017.04
8.0.220.0030.00317.11
8.0.210.0030.00317.02
8.0.200.0030.00317.10
8.0.190.0000.00817.22
8.0.180.0070.00017.16
8.0.170.0000.00917.12
8.0.160.0040.00417.11
8.0.150.0050.00217.04
8.0.140.0000.00717.09
8.0.130.0000.00613.50
8.0.120.0040.00417.02
8.0.110.0000.00717.04
8.0.100.0000.00717.00
8.0.90.0050.00316.95
8.0.80.0090.01317.16
8.0.70.0050.00316.94
8.0.60.0050.00217.15
8.0.50.0080.00017.11
8.0.30.0110.00817.31
8.0.20.0100.00817.69
8.0.10.0020.00517.12
8.0.00.0140.00716.95
7.4.330.0000.00515.16
7.4.320.0030.00316.75
7.4.300.0000.00716.65
7.4.290.0030.00316.76
7.4.280.0080.00016.68
7.4.270.0040.00416.65
7.4.260.0040.00416.73
7.4.250.0040.00416.71
7.4.240.0030.00416.74
7.4.230.0040.00316.84
7.4.220.0090.00916.77
7.4.210.0080.00916.87
7.4.200.0000.00716.79
7.4.190.0070.00016.70
7.4.160.0070.01016.73
7.4.150.0190.00017.40
7.4.140.0050.01217.86
7.4.130.0160.00516.70
7.4.120.0160.00516.82
7.4.110.0110.00616.66
7.4.100.0160.00316.75
7.4.90.0100.01016.84
7.4.80.0070.01019.39
7.4.70.0090.01316.78
7.4.60.0070.01416.84
7.4.50.0000.00916.64
7.4.40.0030.01716.77
7.4.30.0120.00916.61
7.4.00.0100.00615.28
7.3.330.0030.00613.57
7.3.320.0050.00013.59
7.3.310.0040.00416.61
7.3.300.0040.00416.60
7.3.290.0060.00816.57
7.3.280.0090.01016.61
7.3.270.0110.00617.40
7.3.260.0000.02216.55
7.3.250.0110.00916.79
7.3.240.0100.01316.89
7.3.230.0070.01016.61
7.3.210.0090.00916.61
7.3.200.0120.00419.39
7.3.190.0080.00816.41
7.3.180.0040.01116.61
7.3.170.0080.01116.79
7.3.160.0090.00616.54
7.3.120.0090.00415.29
7.3.110.0070.01015.11
7.3.100.0030.01215.25
7.3.90.0050.00715.34
7.3.80.0020.01715.21
7.3.70.0030.00915.22
7.3.60.0020.01215.18
7.3.50.0050.00915.41
7.3.40.0070.00615.22
7.3.30.0030.00815.23
7.3.20.0070.00417.06
7.3.10.0050.00717.11
7.3.00.0070.00816.88
7.2.330.0040.01516.92
7.2.320.0130.00316.99
7.2.310.0120.01216.92
7.2.300.0060.01217.00
7.2.290.0170.00316.94
7.2.250.0090.01215.53
7.2.240.0080.01115.74
7.2.230.0020.01215.70
7.2.220.0030.01015.53
7.2.210.0020.01115.56
7.2.200.0030.00815.55
7.2.190.0060.00515.42
7.2.180.0090.00315.46
7.2.170.0040.01015.34
7.2.160.0070.00515.59
7.2.150.0040.00817.18
7.2.140.0060.00717.13
7.2.130.0070.00817.44
7.2.120.0060.00817.34
7.2.110.0120.00517.14
7.2.100.0000.01617.32
7.2.90.0080.00817.08
7.2.80.0110.00117.14
7.2.70.0050.00817.22
7.2.60.0050.00617.20
7.2.50.0090.00217.26
7.2.40.0040.00717.36
7.2.30.0030.01117.05
7.2.20.0050.00917.11
7.2.10.0080.00717.17
7.2.00.0050.01018.23
7.1.330.0090.00816.21
7.1.320.0040.01316.38
7.1.310.0040.00916.25
7.1.300.0070.00716.22
7.1.290.0070.00916.15
7.1.280.0000.01216.08
7.1.270.0050.00516.08
7.1.260.0100.00616.35
7.1.250.0000.01216.03
7.1.240.0060.01115.99
7.1.230.0090.00516.28
7.1.220.0040.01216.20
7.1.210.0050.00816.14
7.1.200.0080.00416.07
7.1.190.0070.00316.14
7.1.180.0040.01016.10
7.1.170.0080.00716.05
7.1.160.0050.00616.02
7.1.150.0050.01116.27
7.1.140.0070.00716.18
7.1.130.0070.00416.06
7.1.120.0050.01015.99
7.1.110.0070.00716.16
7.1.100.0050.00717.05
7.1.90.0050.01116.28
7.1.80.0050.00916.13
7.1.70.0020.00916.54
7.1.60.0030.01217.34
7.1.50.0060.01116.60
7.1.40.0060.00616.01
7.1.30.0030.01016.28
7.1.20.0030.00916.20
7.1.10.0070.00416.11
7.1.00.0060.03018.33
7.0.330.0050.00615.86
7.0.320.0050.00715.74
7.0.310.0050.00715.78
7.0.300.0070.00515.62
7.0.290.0080.00215.84
7.0.280.0080.00615.70
7.0.270.0040.00715.59
7.0.260.0080.00615.67
7.0.250.0060.00315.79
7.0.240.0050.00915.78
7.0.230.0060.00515.68
7.0.220.0060.00515.54
7.0.210.0080.00315.84
7.0.200.0060.00716.20
7.0.190.0070.00715.80
7.0.180.0050.00915.80
7.0.170.0070.00915.77
7.0.160.0060.00815.71
7.0.150.0060.00615.69
7.0.140.0060.03017.95
7.0.130.0000.01115.88
7.0.120.0050.00715.81
7.0.110.0050.00715.85
7.0.100.0020.01015.75
7.0.90.0050.00715.58
7.0.80.0060.00715.84
7.0.70.0050.00815.61
7.0.60.0100.03017.26
7.0.50.0060.01716.64
7.0.40.0100.02116.01
7.0.30.0140.02516.08
7.0.20.0120.02416.06
7.0.10.0050.03116.11
7.0.00.0050.02016.09
5.6.400.0070.00714.86
5.6.390.0030.00914.69
5.6.380.0070.00614.59
5.6.370.0080.00614.58
5.6.360.0070.00414.69
5.6.350.0060.00514.79
5.6.340.0100.00314.71
5.6.330.0080.00514.76
5.6.320.0070.00714.67
5.6.310.0060.00714.72
5.6.300.0040.01114.76
5.6.290.0050.00814.87
5.6.280.0020.01014.73
5.6.270.0010.00914.82
5.6.260.0040.00614.85
5.6.250.0040.00514.89
5.6.240.0050.00814.56
5.6.230.0050.01014.55
5.6.220.0070.00814.77
5.6.210.0090.03016.90
5.6.200.0030.02816.00
5.6.190.0060.03416.83
5.6.180.0110.02916.99
5.6.170.0070.02616.79
5.6.160.0050.02016.77
5.6.150.0060.03716.02
5.6.140.0080.02716.08
5.6.130.0040.02516.05
5.6.120.0070.03316.83
5.6.110.0070.03316.96
5.6.100.0100.02517.03
5.6.90.0080.03616.92
5.6.80.0090.03016.60
5.6.70.0070.01014.65
5.6.60.0080.00614.53
5.6.50.0050.01114.75
5.6.40.0050.00914.47
5.6.30.0050.00814.54
5.6.20.0090.00614.41
5.6.10.0060.00614.74
5.6.00.0050.00714.55
5.5.380.0020.01314.72
5.5.370.0070.00314.72
5.5.360.0070.01014.51
5.5.350.0030.01416.72
5.5.340.0080.02916.02
5.5.330.0050.02216.57
5.5.320.0180.02716.70
5.5.310.0170.03116.57
5.5.300.0040.03515.90
5.5.290.0080.03015.94
5.5.280.0080.02716.86
5.5.270.0050.01916.83
5.5.260.0100.02916.75
5.5.250.0090.03116.76
5.5.240.0020.02016.63
5.5.230.0030.01014.55
5.5.220.0070.00714.85
5.5.210.0020.01314.39
5.5.200.0050.00914.62
5.5.190.0090.00614.48
5.5.180.0080.00614.58
5.5.170.0020.01114.54
5.5.160.0020.00914.46
5.5.150.0030.01014.79
5.5.140.0060.00614.67
5.5.130.0060.00514.62
5.5.120.0050.01014.55
5.5.110.0060.00614.44
5.5.100.0050.01114.57
5.5.90.0090.00514.69
5.5.80.0040.01114.62
5.5.70.0000.01214.49
5.5.60.0060.00814.44
5.5.50.0050.01014.46
5.5.40.0060.00914.60
5.5.30.0060.00714.42
5.5.20.0030.01214.42
5.5.10.0110.00314.55
5.5.00.0110.00514.44
5.4.450.1320.01614.37
5.4.440.1340.01914.24
5.4.430.1060.01914.31
5.4.420.1340.01514.42
5.4.410.0600.01914.23
5.4.400.0940.01614.17
5.4.390.1300.01414.06
5.4.380.1340.01714.18
5.4.370.1480.01614.22
5.4.360.1520.01814.32
5.4.350.1400.01814.19
5.4.340.1370.01514.25
5.4.330.0030.01011.65
5.4.320.1550.01914.17
5.4.310.1200.02114.08
5.4.300.1500.02114.20
5.4.290.1550.01814.10
5.4.280.1410.01614.23
5.4.270.1580.01314.13
5.4.260.1470.02014.18
5.4.250.1490.02014.12
5.4.240.1490.02014.11
5.4.230.1200.01814.15
5.4.220.1330.01714.22
5.4.210.1400.01514.05
5.4.200.1220.01514.15
5.4.190.1210.01514.27
5.4.180.1300.01714.13
5.4.170.1270.01314.14
5.4.160.1230.01614.27
5.4.150.1330.01814.09
5.4.140.1550.01713.37
5.4.130.1230.01213.25
5.4.120.1190.01713.37
5.4.110.1470.01613.40
5.4.100.1430.01713.31
5.4.90.1450.01513.30
5.4.80.1210.01613.39
5.4.70.1210.01813.38
5.4.60.1190.01613.33
5.4.50.1240.01713.35
5.4.40.1470.02113.36
5.4.30.1520.01813.33
5.4.20.1660.01413.26
5.4.10.1390.01313.30
5.4.00.1300.01513.17
5.3.290.1420.01912.56
5.3.280.1150.01612.48
5.3.270.1150.02012.54
5.3.260.1350.01112.55
5.3.250.1410.01612.41
5.3.240.1270.01912.46
5.3.230.1250.01612.50
5.3.220.1470.01612.39
5.3.210.1450.01712.38
5.3.200.1500.01812.49
5.3.190.1410.01612.43
5.3.180.1240.01612.51
5.3.170.1280.01412.54
5.3.160.1240.01712.56
5.3.150.1190.01812.43
5.3.140.1460.01812.50
5.3.130.1280.01912.49
5.3.120.1540.01212.56
5.3.110.1350.01012.41
5.3.100.1370.01812.24
5.3.90.1290.01812.40
5.3.80.1340.01712.26
5.3.70.1240.01412.27
5.3.60.1280.01812.38
5.3.50.1370.01712.31
5.3.40.1870.01812.25
5.3.30.1050.01612.33
5.3.20.1340.01712.27
5.3.10.1030.01812.06
5.3.00.1240.01712.00
5.2.170.3870.03311.59
5.2.160.3800.03011.43
5.2.150.3500.02711.35
5.2.140.3400.03011.34
5.2.130.3330.02011.55
5.2.120.3200.03311.40
5.2.110.3370.02311.50
5.2.100.3630.03311.43
5.2.90.2670.03011.35
5.2.80.3000.02311.44
5.2.70.2330.03011.43
5.2.60.2970.03011.33
5.2.50.3870.01711.26
5.2.40.2430.02311.36
5.2.30.2430.02711.19
5.2.20.2470.02311.41
5.2.10.2330.03011.05
5.2.00.2070.03011.01
5.1.60.2430.02010.41
5.1.50.2300.02710.40
5.1.40.2970.02310.40
5.1.30.1600.03710.53
5.1.20.2170.02310.63
5.1.10.2300.02710.46
5.1.00.2870.02710.49
5.0.50.1330.02710.40
5.0.40.1670.02310.40
5.0.30.1570.02710.40
5.0.20.1670.02310.40
5.0.10.1830.01710.40
5.0.00.1430.02710.40
4.4.90.1170.01310.40
4.4.80.1200.01310.40
4.4.70.1200.01310.40
4.4.60.1070.01710.40
4.4.50.1230.01010.40
4.4.40.1430.02010.40
4.4.30.1430.01710.40
4.4.20.1200.01710.40
4.4.10.1100.02010.40
4.4.00.1600.02310.40
4.3.110.1670.01710.40
4.3.100.1400.02310.40
4.3.90.1530.01710.40
4.3.80.1830.02010.40
4.3.70.1730.01710.40
4.3.60.1730.01710.40
4.3.50.1400.01710.40
4.3.40.1470.02310.40
4.3.30.1070.02010.40
4.3.20.0800.02010.40
4.3.10.0900.02310.40
4.3.00.0770.01710.40

preferences:
41.32 ms | 401 KiB | 5 Q