3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* Дана сумма, находящаяся в банке на счету, в рублях. Вывести ее в текстовом виде вроде "шестнадцать миллионов десять тысяч три (16010003) рубля". */ error_reporting(-1); mb_internal_encoding('UTF-8'); /* Делает первую букву предложения заглавной */ function makeFirstLetterUppercase($text) { $text = mb_strtoupper(mb_substr($text, 0, 1)) . mb_substr($text, 1, NULL); return $text; } /* Возвращает соответствующую числу форму слова: 1 рубль, 2 рубля, 5 рублей */ function inclineWord($number, $word1, $word2, $word5) { $exception = $number; $number = $number % 10; if (($number == 1) && ($exception != 11)) { return $word1; } elseif (($number >= 2) && ($number <= 4) && (($exception <= 10) || ($exception >= 15))) { return $word2; } else { return $word5; } } /* Преобразует числа от 0 до 999 в текст. Параметр $isFemale равен нулю, если мы считаем число для мужского рода (один рубль), и 1 — для женского (одна тысяча) */ function smallNumberToText($number, $isFemale) { $spelling = array( 0 => 'ноль', 10 => 'десять', 100 => 'сто', 1 => 'один', 11 => 'одиннадцать', 20 => 'двадцать', 200 => 'двести', 2 => 'два', 12 => 'двенадцать', 30 => 'тридцать', 300 => 'триста', 3 => 'три', 13 => 'тринадцать', 40 => 'сорок', 400 => 'четыреста', 4 => 'четыре', 14 => 'четырнадцать', 50 => 'пятьдесят', 500 => 'пятьсот', 5 => 'пять', 15 => 'пятнадцать', 60 => 'шестьдесят', 600 => 'шестьсот', 6 => 'шесть', 16 => 'шестнадцать', 70 => 'семьдесят', 700 => 'семьсот', 7 => 'семь', 17 => 'семнадцать', 80 => 'восемьдесят', 800 => 'восемьсот', 8 => 'восемь', 18 => 'восемнадцать', 90 => 'девяносто', 900 => 'девятьсот', 9 => 'девять', 19 => 'девятнадцать' ); if (($isFemale == 1) || ($isFemale == 2)) { $spelling[1] = 'одна'; $spelling[2] = 'две'; } $firstDigit = floor($number / 100) * 100; // Получаем кол-во сотен (900 из числа 985) $middleDigit = floor(($number % 100) / 10) * 10; // Получаем кол-во десятков (80 из числа 985) $lastDigit = $number % 10; // Получаем кол-во единиц (5 из числа 985) if ($firstDigit != 0) { $text[] = $spelling[$firstDigit]; } if (($middleDigit != 0) && ($middleDigit >= 20)) { $text[] = $spelling[$middleDigit]; } elseif (($middleDigit != 0) && ($middleDigit <= 19)) { $text[] = $spelling[$middleDigit + $lastDigit]; $lastDigit = 0; } if ($lastDigit != 0) { $text[] = $spelling[$lastDigit]; } return implode($text, ' '); } function numberToText($number) { $millions = floor($number / 1000000); // Получаем кол-во миллинов (99 из числа 99965985) $thousands = floor(($number % 1000000) / 1000); // Получаем кол-во тысяч (965 из числа 99965985) $hundreds = $number % 1000; // Получаем кол-во сотен (985 из числа 99965985) if ($millions != 0) { $text[] = smallNumberToText($millions, 0) . inclineWord($millions % 10, ' миллион', ' миллиона', ' миллионов'); } if ($thousands != 0) { $text[] = smallNumberToText($thousands, $thousands % 10) . inclineWord($thousands % 10, ' тысяча', ' тысячи', ' тысяч'); } if ($hundreds != 0) { $text[] = smallNumberToText($hundreds, 0) . inclineWord($hundreds, ' рубль', ' рубля', ' рублей'); } if ($number == 0) { $text[] = '0 рублей'; } $text = makeFirstLetterUppercase(implode($text, ' ') . " ({$number})"); return $text; } $amount1 = mt_rand(0, 99999999); $text1 = numberToText($amount1); echo "На вашем счету: {$text1}\n"; $amount2 = mt_rand(0, 99999999); $text2 = numberToText($amount2); echo "На вашем счету: {$text2}\n"; $amount3 = mt_rand(0, 99999999); $text3 = numberToText($amount3); echo "На вашем счету: {$text3}\n"; $amount4 = mt_rand(0, 99999999); $text4 = numberToText($amount4); echo "На вашем счету: {$text4}\n"; $amount5 = mt_rand(0, 99999999); $text5 = numberToText($amount5); echo "На вашем счету: {$text5}\n"; $amount6 = mt_rand(0, 99999999); $text6 = numberToText($amount6); echo "На вашем счету: {$text6}\n"; for ($i = 0; $i < 101; $i++) { $text7 = numberToText($i); echo "На вашем счету: {$text7}\n"; }

Abusive script

This script was stopped while abusing our resources

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.4.00.0060.01214.75
7.3.120.0090.00914.78
7.3.110.0070.01114.90
7.3.100.0090.00614.77
7.3.90.0030.00915.16
7.3.80.0060.00915.02
7.3.70.0060.00914.60
7.3.60.0100.00714.70
7.3.50.0080.00414.91
7.3.40.0070.01015.00
7.3.30.0000.01514.93
7.3.20.0110.00316.70
7.3.10.0100.00616.52
7.3.00.0060.00616.76
7.2.250.0000.01614.91
7.2.240.0140.00715.36
7.2.230.0070.01314.97
7.2.220.0000.01114.95
7.2.210.0030.01515.36
7.2.200.0100.00715.29
7.2.190.0000.01715.05
7.2.180.0040.00914.89
7.2.170.0060.01315.15
7.1.330.0060.00915.69
7.1.320.0060.00915.92
7.1.310.0060.00915.89
7.1.300.0100.00615.84
7.1.290.0090.00616.00
7.1.280.0070.01015.91
7.1.270.0100.00615.97
7.1.260.0170.00015.91
7.1.70.0060.00817.39
7.1.60.0060.00917.38
7.1.50.0030.01917.00
7.1.40.0230.00734.33
7.1.30.0100.02334.36
7.1.20.0230.01034.46
7.1.10.0070.01016.50
7.1.00.0030.01316.68
7.0.200.0140.00716.71
7.0.180.0000.02316.14
7.0.170.0100.00716.23
7.0.160.0030.01316.23
7.0.150.0100.01316.37
7.0.140.0030.01016.03
7.0.130.0070.01016.64
7.0.120.0070.01016.42
7.0.110.0070.01016.22
7.0.100.0070.01016.44
7.0.90.0030.01316.43
7.0.80.0000.01316.38
7.0.70.0000.01716.47
7.0.60.0030.01015.96
7.0.50.0100.00316.27
7.0.40.0030.01716.43
7.0.30.0000.01716.47
7.0.20.0030.01016.66
7.0.10.0070.01016.53
7.0.00.0000.01316.46

preferences:
42.77 ms | 403 KiB | 5 Q