3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Staring straight up into the sky ... oh my my error_reporting(-1); mb_internal_encoding('utf-8'); /* Возвращает соответствующую числу форму слова: 1 рубль, 2 рубля, 5 рублей */ function inclineWord($number, $key) { $formsOfWords = array( 0 => array("рубль", "рубля", "рублей"), 1 => array("тысяча", "тысячи", "тысяч"), 2 => array("миллион", "миллиона", "миллионов") ); $number = $number % 10; if ($number >= 11 && $number <= 14){ return $formsOfWords[$key][2]; }if ($number == 1){ return $formsOfWords[$key][0]; } elseif ($number > 1 && $number < 5) { return $formsOfWords[$key][1]; } else { return $formsOfWords[$key][2]; } } /* Преобразует числа от 0 до 999 в текст. Параметр $isFemale равен нулю, если мы считаем число для мужского рода (один рубль), и 1 — для женского (одна тысяча) */ function smallNumberToText($number, $isFemale) { $spelling = array( 0 => 'ноль', 1 => 'один', 2 => 'два', 3 => 'три', 4 => 'четыре', 5 => 'пять', 6 => 'шесть', 7 => 'семь', 8 => 'восемь', 9 => 'девять', 10 => 'десять', 11 => 'одиннадцать', 12 => 'двенадцать', 13 => 'тринадцать', 14 => 'четырнадцать', 15 => 'пятнадцать', 16 => 'шестнадцать', 17 => 'семнадцать', 18 => 'восемнадцать', 19 => 'девятнадцать', 20 => 'двадцать', 30 => 'тридцать', 40 => 'сорок', 50 => 'пятьдесят', 60 => 'шестьдесят', 70 => 'семьдесят', 80 => 'восемьдесят', 90 => 'девяносто', 100 => 'сто', 200 => 'двести', 300 => 'триста', 400 => 'четыреста', 500 => 'пятьсот', 600 => 'шестьсот', 700 => 'семьсот', 800 => 'восемьсот', 900 => 'девятьсот' ); $femaleSpelling = array( 1 => 'одна', 2 => 'две' ); $digitsByWord = ""; if ($number == 0){ return $spelling[0]; } if ($number >= 100){ $digits = floor($number / 100) * 100; $digitsByWord = $spelling[$digits].' '; $number = $number % 100; } if ($number > 9 && $number <20){ $digitsByWord = $digitsByWord.$spelling[$number].' '; return $digitsByWord; } if ($number > 19){ $digits = floor($number / 10) * 10; $digitsByWord = $digitsByWord.$spelling[$digits].' '; $number = $number % 10; } if ($number > 0){ if ($isFemale == 1 && $number == 1){ $digitsByWord = $digitsByWord.$femaleSpelling[1].' '; } elseif ($isFemale == 1 && $number == 2) { $digitsByWord = $digitsByWord.$femaleSpelling[2].' '; } else { $digitsByWord = $digitsByWord.$spelling[$number].' '; } } return $digitsByWord; } function numberToText($number) { for ($i = 0; $i < 3; $i++){ $threeDigits[$i] = $number % 1000; $number =floor($number / 1000); } // $threeDigits = array_reverse($threeDigits); // for ($i = 0; $i < 2; $i++){ // if ($threeDigits[$i] == 0){ // array_shift($threeDigits); // } // } $threeDigitsWords = array(); foreach ($threeDigits as $key => $value) { if ($value == 0){ break; } if ($key == 1){ $isFemale = 1; } else { $isFemale = 0; } $threeDigitsWords[$key] = smallNumberToText($value, $isFemale); $threeDigitsWords[$key] = $threeDigitsWords[$key].inclineWord($value, $key); } $threeDigitsWords = array_reverse($threeDigitsWords); return implode(" ", $threeDigitsWords); } $amount1 = 1000001; echo $amount1, "\n"; $text1 = numberToText($amount1); echo "На вашем счету {$text1}\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ukHEA
function name:  (null)
number of ops:  18
compiled vars:  !0 = $amount1, !1 = $text1
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   INIT_FCALL                                               'error_reporting'
          1        SEND_VAL                                                 -1
          2        DO_ICALL                                                 
    5     3        INIT_FCALL                                               'mb_internal_encoding'
          4        SEND_VAL                                                 'utf-8'
          5        DO_ICALL                                                 
  147     6        ASSIGN                                                   !0, 1000001
  148     7        ECHO                                                     !0
          8        ECHO                                                     '%0A'
  149     9        INIT_FCALL                                               'numbertotext'
         10        SEND_VAR                                                 !0
         11        DO_FCALL                                      0  $5      
         12        ASSIGN                                                   !1, $5
  151    13        ROPE_INIT                                     3  ~8      '%D0%9D%D0%B0+%D0%B2%D0%B0%D1%88%D0%B5%D0%BC+%D1%81%D1%87%D0%B5%D1%82%D1%83+'
         14        ROPE_ADD                                      1  ~8      ~8, !1
         15        ROPE_END                                      2  ~7      ~8, '%0A'
         16        ECHO                                                     ~7
         17      > RETURN                                                   1

Function inclineword:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 13
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 19
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
2 jumps found. (Code = 46) Position 1 = 21, Position 2 = 23
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 28
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
Branch analysis from position: 9
filename:       /in/ukHEA
function name:  inclineWord
number of ops:  32
compiled vars:  !0 = $number, !1 = $key, !2 = $formsOfWords
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   10     2        ASSIGN                                                   !2, <array>
   16     3        MOD                                              ~4      !0, 10
          4        ASSIGN                                                   !0, ~4
   18     5        IS_SMALLER_OR_EQUAL                              ~6      11, !0
          6      > JMPZ_EX                                          ~6      ~6, ->9
          7    >   IS_SMALLER_OR_EQUAL                              ~7      !0, 14
          8        BOOL                                             ~6      ~7
          9    > > JMPZ                                                     ~6, ->13
   19    10    >   FETCH_DIM_R                                      ~8      !2, !1
         11        FETCH_DIM_R                                      ~9      ~8, 2
         12      > RETURN                                                   ~9
   20    13    >   IS_EQUAL                                                 !0, 1
         14      > JMPZ                                                     ~10, ->19
   21    15    >   FETCH_DIM_R                                      ~11     !2, !1
         16        FETCH_DIM_R                                      ~12     ~11, 0
         17      > RETURN                                                   ~12
         18*       JMP                                                      ->31
   22    19    >   IS_SMALLER                                       ~13     1, !0
         20      > JMPZ_EX                                          ~13     ~13, ->23
         21    >   IS_SMALLER                                       ~14     !0, 5
         22        BOOL                                             ~13     ~14
         23    > > JMPZ                                                     ~13, ->28
   23    24    >   FETCH_DIM_R                                      ~15     !2, !1
         25        FETCH_DIM_R                                      ~16     ~15, 1
         26      > RETURN                                                   ~16
         27*       JMP                                                      ->31
   25    28    >   FETCH_DIM_R                                      ~17     !2, !1
         29        FETCH_DIM_R                                      ~18     ~17, 2
         30      > RETURN                                                   ~18
   27    31*     > RETURN                                                   null

End of function inclineword

Function smallnumbertotext:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 22
Branch analysis from position: 11
2 jumps found. (Code = 46) Position 1 = 24, Position 2 = 26
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 32
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 46
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 72
Branch analysis from position: 48
2 jumps found. (Code = 46) Position 1 = 50, Position 2 = 52
Branch analysis from position: 50
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 58
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 72
Branch analysis from position: 72
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 58
2 jumps found. (Code = 46) Position 1 = 60, Position 2 = 62
Branch analysis from position: 60
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 68
Branch analysis from position: 63
1 jumps found. (Code = 42) Position 1 = 72
Branch analysis from position: 72
Branch analysis from position: 68
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 62
Branch analysis from position: 52
Branch analysis from position: 72
Branch analysis from position: 46
Branch analysis from position: 26
Branch analysis from position: 22
filename:       /in/ukHEA
function name:  smallNumberToText
number of ops:  74
compiled vars:  !0 = $number, !1 = $isFemale, !2 = $spelling, !3 = $femaleSpelling, !4 = $digitsByWord, !5 = $digits
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   36     2        ASSIGN                                                   !2, <array>
   76     3        ASSIGN                                                   !3, <array>
   80     4        ASSIGN                                                   !4, ''
   82     5        IS_EQUAL                                                 !0, 0
          6      > JMPZ                                                     ~9, ->9
   83     7    >   FETCH_DIM_R                                      ~10     !2, 0
          8      > RETURN                                                   ~10
   85     9    >   IS_SMALLER_OR_EQUAL                                      100, !0
         10      > JMPZ                                                     ~11, ->22
   86    11    >   INIT_FCALL                                               'floor'
         12        DIV                                              ~12     !0, 100
         13        SEND_VAL                                                 ~12
         14        DO_ICALL                                         $13     
         15        MUL                                              ~14     $13, 100
         16        ASSIGN                                                   !5, ~14
   87    17        FETCH_DIM_R                                      ~16     !2, !5
         18        CONCAT                                           ~17     ~16, '+'
         19        ASSIGN                                                   !4, ~17
   88    20        MOD                                              ~19     !0, 100
         21        ASSIGN                                                   !0, ~19
   90    22    >   IS_SMALLER                                       ~21     9, !0
         23      > JMPZ_EX                                          ~21     ~21, ->26
         24    >   IS_SMALLER                                       ~22     !0, 20
         25        BOOL                                             ~21     ~22
         26    > > JMPZ                                                     ~21, ->32
   91    27    >   FETCH_DIM_R                                      ~23     !2, !0
         28        CONCAT                                           ~24     !4, ~23
         29        CONCAT                                           ~25     ~24, '+'
         30        ASSIGN                                                   !4, ~25
   92    31      > RETURN                                                   !4
   94    32    >   IS_SMALLER                                               19, !0
         33      > JMPZ                                                     ~27, ->46
   95    34    >   INIT_FCALL                                               'floor'
         35        DIV                                              ~28     !0, 10
         36        SEND_VAL                                                 ~28
         37        DO_ICALL                                         $29     
         38        MUL                                              ~30     $29, 10
         39        ASSIGN                                                   !5, ~30
   96    40        FETCH_DIM_R                                      ~32     !2, !5
         41        CONCAT                                           ~33     !4, ~32
         42        CONCAT                                           ~34     ~33, '+'
         43        ASSIGN                                                   !4, ~34
   97    44        MOD                                              ~36     !0, 10
         45        ASSIGN                                                   !0, ~36
   99    46    >   IS_SMALLER                                               0, !0
         47      > JMPZ                                                     ~38, ->72
  100    48    >   IS_EQUAL                                         ~39     !1, 1
         49      > JMPZ_EX                                          ~39     ~39, ->52
         50    >   IS_EQUAL                                         ~40     !0, 1
         51        BOOL                                             ~39     ~40
         52    > > JMPZ                                                     ~39, ->58
  101    53    >   FETCH_DIM_R                                      ~41     !3, 1
         54        CONCAT                                           ~42     !4, ~41
         55        CONCAT                                           ~43     ~42, '+'
         56        ASSIGN                                                   !4, ~43
         57      > JMP                                                      ->72
  102    58    >   IS_EQUAL                                         ~45     !1, 1
         59      > JMPZ_EX                                          ~45     ~45, ->62
         60    >   IS_EQUAL                                         ~46     !0, 2
         61        BOOL                                             ~45     ~46
         62    > > JMPZ                                                     ~45, ->68
  103    63    >   FETCH_DIM_R                                      ~47     !3, 2
         64        CONCAT                                           ~48     !4, ~47
         65        CONCAT                                           ~49     ~48, '+'
         66        ASSIGN                                                   !4, ~49
         67      > JMP                                                      ->72
  105    68    >   FETCH_DIM_R                                      ~51     !2, !0
         69        CONCAT                                           ~52     !4, ~51
         70        CONCAT                                           ~53     ~52, '+'
         71        ASSIGN                                                   !4, ~53
  109    72    > > RETURN                                                   !4
  110    73*     > RETURN                                                   null

End of function smallnumbertotext

Function numbertotext:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 3
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 41
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 41
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 21
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 25
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 41
Branch analysis from position: 41
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 3
Branch analysis from position: 14
Branch analysis from position: 3
filename:       /in/ukHEA
function name:  numberToText
number of ops:  52
compiled vars:  !0 = $number, !1 = $i, !2 = $threeDigits, !3 = $threeDigitsWords, !4 = $value, !5 = $key, !6 = $isFemale
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  112     0  E >   RECV                                             !0      
  114     1        ASSIGN                                                   !1, 0
          2      > JMP                                                      ->12
  115     3    >   MOD                                              ~9      !0, 1000
          4        ASSIGN_DIM                                               !2, !1
          5        OP_DATA                                                  ~9
  116     6        INIT_FCALL                                               'floor'
          7        DIV                                              ~10     !0, 1000
          8        SEND_VAL                                                 ~10
          9        DO_ICALL                                         $11     
         10        ASSIGN                                                   !0, $11
  114    11        PRE_INC                                                  !1
         12    >   IS_SMALLER                                               !1, 3
         13      > JMPNZ                                                    ~14, ->3
  127    14    >   ASSIGN                                                   !3, <array>
  128    15      > FE_RESET_R                                       $16     !2, ->41
         16    > > FE_FETCH_R                                       ~17     $16, !4, ->41
         17    >   ASSIGN                                                   !5, ~17
  129    18        IS_EQUAL                                                 !4, 0
         19      > JMPZ                                                     ~19, ->21
  130    20    > > JMP                                                      ->41
  133    21    >   IS_EQUAL                                                 !5, 1
         22      > JMPZ                                                     ~20, ->25
  134    23    >   ASSIGN                                                   !6, 1
         24      > JMP                                                      ->26
  136    25    >   ASSIGN                                                   !6, 0
  139    26    >   INIT_FCALL                                               'smallnumbertotext'
         27        SEND_VAR                                                 !4
         28        SEND_VAR                                                 !6
         29        DO_FCALL                                      0  $24     
         30        ASSIGN_DIM                                               !3, !5
         31        OP_DATA                                                  $24
  140    32        FETCH_DIM_R                                      ~26     !3, !5
         33        INIT_FCALL                                               'inclineword'
         34        SEND_VAR                                                 !4
         35        SEND_VAR                                                 !5
         36        DO_FCALL                                      0  $27     
         37        CONCAT                                           ~28     ~26, $27
         38        ASSIGN_DIM                                               !3, !5
         39        OP_DATA                                                  ~28
  128    40      > JMP                                                      ->16
         41    >   FE_FREE                                                  $16
  143    42        INIT_FCALL                                               'array_reverse'
         43        SEND_VAR                                                 !3
         44        DO_ICALL                                         $29     
         45        ASSIGN                                                   !3, $29
  144    46        INIT_FCALL                                               'implode'
         47        SEND_VAL                                                 '+'
         48        SEND_VAR                                                 !3
         49        DO_ICALL                                         $31     
         50      > RETURN                                                   $31
  145    51*     > RETURN                                                   null

End of function numbertotext

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.94 ms | 1419 KiB | 26 Q