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 ($key == 1){ $isFemale = 1; } else { $isFemale = 0; } $threeDigitsWords[$key] = smallNumberToText($value, $isFemale); $threeDigitsWords[$key] = $threeDigitsWords[$key].' '.inclineWord($value, $key); } return implode(" ", $threeDigitsWords); } /* Вызовем функцию несколько раз */ $amount1 = 1001; $text1 = numberToText($amount1);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fK367
function name:  (null)
number of ops:  12
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                                                 
  142     6        ASSIGN                                                   !0, 1001
  143     7        INIT_FCALL                                               'numbertotext'
          8        SEND_VAR                                                 !0
          9        DO_FCALL                                      0  $5      
         10        ASSIGN                                                   !1, $5
         11      > 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/fK367
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 = 21
Branch analysis from position: 11
2 jumps found. (Code = 46) Position 1 = 23, Position 2 = 25
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 31
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 45
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 71
Branch analysis from position: 47
2 jumps found. (Code = 46) Position 1 = 49, Position 2 = 51
Branch analysis from position: 49
2 jumps found. (Code = 43) Position 1 = 52, Position 2 = 57
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 71
Branch analysis from position: 71
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 57
2 jumps found. (Code = 46) Position 1 = 59, Position 2 = 61
Branch analysis from position: 59
2 jumps found. (Code = 43) Position 1 = 62, Position 2 = 67
Branch analysis from position: 62
1 jumps found. (Code = 42) Position 1 = 71
Branch analysis from position: 71
Branch analysis from position: 67
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 61
Branch analysis from position: 51
Branch analysis from position: 71
Branch analysis from position: 45
Branch analysis from position: 25
Branch analysis from position: 21
filename:       /in/fK367
function name:  smallNumberToText
number of ops:  73
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, ->21
   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        ASSIGN                                                   !4, ~16
   88    19        MOD                                              ~18     !0, 100
         20        ASSIGN                                                   !0, ~18
   90    21    >   IS_SMALLER                                       ~20     9, !0
         22      > JMPZ_EX                                          ~20     ~20, ->25
         23    >   IS_SMALLER                                       ~21     !0, 20
         24        BOOL                                             ~20     ~21
         25    > > JMPZ                                                     ~20, ->31
   91    26    >   CONCAT                                           ~22     !4, '+'
         27        FETCH_DIM_R                                      ~23     !2, !0
         28        CONCAT                                           ~24     ~22, ~23
         29        ASSIGN                                                   !4, ~24
   92    30      > RETURN                                                   !4
   94    31    >   IS_SMALLER                                               19, !0
         32      > JMPZ                                                     ~26, ->45
   95    33    >   INIT_FCALL                                               'floor'
         34        DIV                                              ~27     !0, 10
         35        SEND_VAL                                                 ~27
         36        DO_ICALL                                         $28     
         37        MUL                                              ~29     $28, 10
         38        ASSIGN                                                   !5, ~29
   96    39        CONCAT                                           ~31     !4, '+'
         40        FETCH_DIM_R                                      ~32     !2, !5
         41        CONCAT                                           ~33     ~31, ~32
         42        ASSIGN                                                   !4, ~33
   97    43        MOD                                              ~35     !0, 10
         44        ASSIGN                                                   !0, ~35
   99    45    >   IS_SMALLER                                               0, !0
         46      > JMPZ                                                     ~37, ->71
  100    47    >   IS_EQUAL                                         ~38     !1, 1
         48      > JMPZ_EX                                          ~38     ~38, ->51
         49    >   IS_EQUAL                                         ~39     !0, 1
         50        BOOL                                             ~38     ~39
         51    > > JMPZ                                                     ~38, ->57
  101    52    >   CONCAT                                           ~40     !4, '+'
         53        FETCH_DIM_R                                      ~41     !3, 1
         54        CONCAT                                           ~42     ~40, ~41
         55        ASSIGN                                                   !4, ~42
         56      > JMP                                                      ->71
  102    57    >   IS_EQUAL                                         ~44     !1, 1
         58      > JMPZ_EX                                          ~44     ~44, ->61
         59    >   IS_EQUAL                                         ~45     !0, 2
         60        BOOL                                             ~44     ~45
         61    > > JMPZ                                                     ~44, ->67
  103    62    >   CONCAT                                           ~46     !4, '+'
         63        FETCH_DIM_R                                      ~47     !3, 2
         64        CONCAT                                           ~48     ~46, ~47
         65        ASSIGN                                                   !4, ~48
         66      > JMP                                                      ->71
  105    67    >   CONCAT                                           ~50     !4, '+'
         68        FETCH_DIM_R                                      ~51     !2, !0
         69        CONCAT                                           ~52     ~50, ~51
         70        ASSIGN                                                   !4, ~52
  109    71    > > RETURN                                                   !4
  110    72*     > 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
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 20
Branch analysis from position: 29
2 jumps found. (Code = 77) Position 1 = 31, Position 2 = 54
Branch analysis from position: 31
2 jumps found. (Code = 78) Position 1 = 32, Position 2 = 54
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
Branch analysis from position: 54
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 54
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 26
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 20
Branch analysis from position: 29
Branch analysis from position: 20
Branch analysis from position: 26
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/fK367
function name:  numberToText
number of ops:  61
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
  119    14    >   INIT_FCALL                                               'array_reverse'
         15        SEND_VAR                                                 !2
         16        DO_ICALL                                         $15     
         17        ASSIGN                                                   !2, $15
  121    18        ASSIGN                                                   !1, 0
         19      > JMP                                                      ->27
  122    20    >   FETCH_DIM_R                                      ~18     !2, !1
         21        IS_EQUAL                                                 ~18, 0
         22      > JMPZ                                                     ~19, ->26
  123    23    >   INIT_FCALL                                               'array_shift'
         24        SEND_REF                                                 !2
         25        DO_ICALL                                                 
  121    26    >   PRE_INC                                                  !1
         27    >   IS_SMALLER                                               !1, 2
         28      > JMPNZ                                                    ~22, ->20
  127    29    >   ASSIGN                                                   !3, <array>
  128    30      > FE_RESET_R                                       $24     !2, ->54
         31    > > FE_FETCH_R                                       ~25     $24, !4, ->54
         32    >   ASSIGN                                                   !5, ~25
  129    33        IS_EQUAL                                                 !5, 1
         34      > JMPZ                                                     ~27, ->37
  130    35    >   ASSIGN                                                   !6, 1
         36      > JMP                                                      ->38
  132    37    >   ASSIGN                                                   !6, 0
  134    38    >   INIT_FCALL                                               'smallnumbertotext'
         39        SEND_VAR                                                 !4
         40        SEND_VAR                                                 !6
         41        DO_FCALL                                      0  $31     
         42        ASSIGN_DIM                                               !3, !5
         43        OP_DATA                                                  $31
  135    44        FETCH_DIM_R                                      ~33     !3, !5
         45        CONCAT                                           ~34     ~33, '+'
         46        INIT_FCALL                                               'inclineword'
         47        SEND_VAR                                                 !4
         48        SEND_VAR                                                 !5
         49        DO_FCALL                                      0  $35     
         50        CONCAT                                           ~36     ~34, $35
         51        ASSIGN_DIM                                               !3, !5
         52        OP_DATA                                                  ~36
  128    53      > JMP                                                      ->31
         54    >   FE_FREE                                                  $24
  138    55        INIT_FCALL                                               'implode'
         56        SEND_VAL                                                 '+'
         57        SEND_VAR                                                 !3
         58        DO_ICALL                                         $37     
         59      > RETURN                                                   $37
  139    60*     > RETURN                                                   null

End of function numbertotext

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
180.86 ms | 1415 KiB | 28 Q