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); } $threeDigitsWords = array(); foreach ($threeDigits as $key => $value) { if ($value == 0 && $key != 0){ continue; } 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 = mt_rand(1,999999999); echo $amount1, "\n"; $text1 = numberToText($amount1); echo "На вашем счету {$text1}\n"; $amount2 = mt_rand(1,999999999); echo $amount2, "\n"; $text2 = numberToText($amount2); echo "На вашем счету {$text2}\n"; $amount3 = mt_rand(1,999999999); echo $amount3, "\n"; $text3 = numberToText($amount3); echo "На вашем счету {$text3}\n"; $amount4 = mt_rand(1,999999999); echo $amount4, "\n"; $text4 = numberToText($amount4); echo "На вашем счету {$text4}\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GLjK8
function name:  (null)
number of ops:  67
compiled vars:  !0 = $amount1, !1 = $text1, !2 = $amount2, !3 = $text2, !4 = $amount3, !5 = $text3, !6 = $amount4, !7 = $text4
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                                                 
  141     6        INIT_FCALL                                               'mt_rand'
          7        SEND_VAL                                                 1
          8        SEND_VAL                                                 999999999
          9        DO_ICALL                                         $10     
         10        ASSIGN                                                   !0, $10
  142    11        ECHO                                                     !0
         12        ECHO                                                     '%0A'
  143    13        INIT_FCALL                                               'numbertotext'
         14        SEND_VAR                                                 !0
         15        DO_FCALL                                      0  $12     
         16        ASSIGN                                                   !1, $12
  145    17        ROPE_INIT                                     3  ~15     '%D0%9D%D0%B0+%D0%B2%D0%B0%D1%88%D0%B5%D0%BC+%D1%81%D1%87%D0%B5%D1%82%D1%83+'
         18        ROPE_ADD                                      1  ~15     ~15, !1
         19        ROPE_END                                      2  ~14     ~15, '%0A'
         20        ECHO                                                     ~14
  147    21        INIT_FCALL                                               'mt_rand'
         22        SEND_VAL                                                 1
         23        SEND_VAL                                                 999999999
         24        DO_ICALL                                         $17     
         25        ASSIGN                                                   !2, $17
  148    26        ECHO                                                     !2
         27        ECHO                                                     '%0A'
  149    28        INIT_FCALL                                               'numbertotext'
         29        SEND_VAR                                                 !2
         30        DO_FCALL                                      0  $19     
         31        ASSIGN                                                   !3, $19
  151    32        ROPE_INIT                                     3  ~22     '%D0%9D%D0%B0+%D0%B2%D0%B0%D1%88%D0%B5%D0%BC+%D1%81%D1%87%D0%B5%D1%82%D1%83+'
         33        ROPE_ADD                                      1  ~22     ~22, !3
         34        ROPE_END                                      2  ~21     ~22, '%0A'
         35        ECHO                                                     ~21
  153    36        INIT_FCALL                                               'mt_rand'
         37        SEND_VAL                                                 1
         38        SEND_VAL                                                 999999999
         39        DO_ICALL                                         $24     
         40        ASSIGN                                                   !4, $24
  154    41        ECHO                                                     !4
         42        ECHO                                                     '%0A'
  155    43        INIT_FCALL                                               'numbertotext'
         44        SEND_VAR                                                 !4
         45        DO_FCALL                                      0  $26     
         46        ASSIGN                                                   !5, $26
  157    47        ROPE_INIT                                     3  ~29     '%D0%9D%D0%B0+%D0%B2%D0%B0%D1%88%D0%B5%D0%BC+%D1%81%D1%87%D0%B5%D1%82%D1%83+'
         48        ROPE_ADD                                      1  ~29     ~29, !5
         49        ROPE_END                                      2  ~28     ~29, '%0A'
         50        ECHO                                                     ~28
  159    51        INIT_FCALL                                               'mt_rand'
         52        SEND_VAL                                                 1
         53        SEND_VAL                                                 999999999
         54        DO_ICALL                                         $31     
         55        ASSIGN                                                   !6, $31
  160    56        ECHO                                                     !6
         57        ECHO                                                     '%0A'
  161    58        INIT_FCALL                                               'numbertotext'
         59        SEND_VAR                                                 !6
         60        DO_FCALL                                      0  $33     
         61        ASSIGN                                                   !7, $33
  163    62        ROPE_INIT                                     3  ~36     '%D0%9D%D0%B0+%D0%B2%D0%B0%D1%88%D0%B5%D0%BC+%D1%81%D1%87%D0%B5%D1%82%D1%83+'
         63        ROPE_ADD                                      1  ~36     ~36, !7
         64        ROPE_END                                      2  ~35     ~36, '%0A'
         65        ECHO                                                     ~35
         66      > 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/GLjK8
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
   20    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
   22    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 = 10
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 23
Branch analysis from position: 12
2 jumps found. (Code = 46) Position 1 = 25, Position 2 = 27
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 33
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 47
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 73
Branch analysis from position: 49
2 jumps found. (Code = 46) Position 1 = 51, Position 2 = 53
Branch analysis from position: 51
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 59
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 59
2 jumps found. (Code = 46) Position 1 = 61, Position 2 = 63
Branch analysis from position: 61
2 jumps found. (Code = 43) Position 1 = 64, Position 2 = 69
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
Branch analysis from position: 69
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 63
Branch analysis from position: 53
Branch analysis from position: 73
Branch analysis from position: 47
Branch analysis from position: 27
Branch analysis from position: 23
filename:       /in/GLjK8
function name:  smallNumberToText
number of ops:  75
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, ->10
   83     7    >   FETCH_DIM_R                                      ~10     !2, 0
          8        CONCAT                                           ~11     ~10, '+'
          9      > RETURN                                                   ~11
   85    10    >   IS_SMALLER_OR_EQUAL                                      100, !0
         11      > JMPZ                                                     ~12, ->23
   86    12    >   INIT_FCALL                                               'floor'
         13        DIV                                              ~13     !0, 100
         14        SEND_VAL                                                 ~13
         15        DO_ICALL                                         $14     
         16        MUL                                              ~15     $14, 100
         17        ASSIGN                                                   !5, ~15
   87    18        FETCH_DIM_R                                      ~17     !2, !5
         19        CONCAT                                           ~18     ~17, '+'
         20        ASSIGN                                                   !4, ~18
   88    21        MOD                                              ~20     !0, 100
         22        ASSIGN                                                   !0, ~20
   90    23    >   IS_SMALLER                                       ~22     9, !0
         24      > JMPZ_EX                                          ~22     ~22, ->27
         25    >   IS_SMALLER                                       ~23     !0, 20
         26        BOOL                                             ~22     ~23
         27    > > JMPZ                                                     ~22, ->33
   91    28    >   FETCH_DIM_R                                      ~24     !2, !0
         29        CONCAT                                           ~25     !4, ~24
         30        CONCAT                                           ~26     ~25, '+'
         31        ASSIGN                                                   !4, ~26
   92    32      > RETURN                                                   !4
   94    33    >   IS_SMALLER                                               19, !0
         34      > JMPZ                                                     ~28, ->47
   95    35    >   INIT_FCALL                                               'floor'
         36        DIV                                              ~29     !0, 10
         37        SEND_VAL                                                 ~29
         38        DO_ICALL                                         $30     
         39        MUL                                              ~31     $30, 10
         40        ASSIGN                                                   !5, ~31
   96    41        FETCH_DIM_R                                      ~33     !2, !5
         42        CONCAT                                           ~34     !4, ~33
         43        CONCAT                                           ~35     ~34, '+'
         44        ASSIGN                                                   !4, ~35
   97    45        MOD                                              ~37     !0, 10
         46        ASSIGN                                                   !0, ~37
   99    47    >   IS_SMALLER                                               0, !0
         48      > JMPZ                                                     ~39, ->73
  100    49    >   IS_EQUAL                                         ~40     !1, 1
         50      > JMPZ_EX                                          ~40     ~40, ->53
         51    >   IS_EQUAL                                         ~41     !0, 1
         52        BOOL                                             ~40     ~41
         53    > > JMPZ                                                     ~40, ->59
  101    54    >   FETCH_DIM_R                                      ~42     !3, 1
         55        CONCAT                                           ~43     !4, ~42
         56        CONCAT                                           ~44     ~43, '+'
         57        ASSIGN                                                   !4, ~44
  100    58      > JMP                                                      ->73
  102    59    >   IS_EQUAL                                         ~46     !1, 1
         60      > JMPZ_EX                                          ~46     ~46, ->63
         61    >   IS_EQUAL                                         ~47     !0, 2
         62        BOOL                                             ~46     ~47
         63    > > JMPZ                                                     ~46, ->69
  103    64    >   FETCH_DIM_R                                      ~48     !3, 2
         65        CONCAT                                           ~49     !4, ~48
         66        CONCAT                                           ~50     ~49, '+'
         67        ASSIGN                                                   !4, ~50
  102    68      > JMP                                                      ->73
  105    69    >   FETCH_DIM_R                                      ~52     !2, !0
         70        CONCAT                                           ~53     !4, ~52
         71        CONCAT                                           ~54     ~53, '+'
         72        ASSIGN                                                   !4, ~54
  109    73    > > RETURN                                                   !4
  110    74*     > 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 = 44
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 44
Branch analysis from position: 17
2 jumps found. (Code = 46) Position 1 = 20, Position 2 = 22
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 24
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 28
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 22
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
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/GLjK8
function name:  numberToText
number of ops:  55
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    >   ASSIGN                                                   !3, <array>
  121    15      > FE_RESET_R                                       $16     !2, ->44
         16    > > FE_FETCH_R                                       ~17     $16, !4, ->44
         17    >   ASSIGN                                                   !5, ~17
  123    18        IS_EQUAL                                         ~19     !4, 0
         19      > JMPZ_EX                                          ~19     ~19, ->22
         20    >   IS_NOT_EQUAL                                     ~20     !5, 0
         21        BOOL                                             ~19     ~20
         22    > > JMPZ                                                     ~19, ->24
  124    23    > > JMP                                                      ->16
  127    24    >   IS_EQUAL                                                 !5, 1
         25      > JMPZ                                                     ~21, ->28
  128    26    >   ASSIGN                                                   !6, 1
  127    27      > JMP                                                      ->29
  130    28    >   ASSIGN                                                   !6, 0
  133    29    >   INIT_FCALL                                               'smallnumbertotext'
         30        SEND_VAR                                                 !4
         31        SEND_VAR                                                 !6
         32        DO_FCALL                                      0  $25     
         33        ASSIGN_DIM                                               !3, !5
         34        OP_DATA                                                  $25
  134    35        FETCH_DIM_R                                      ~27     !3, !5
         36        INIT_FCALL                                               'inclineword'
         37        SEND_VAR                                                 !4
         38        SEND_VAR                                                 !5
         39        DO_FCALL                                      0  $28     
         40        CONCAT                                           ~29     ~27, $28
         41        ASSIGN_DIM                                               !3, !5
         42        OP_DATA                                                  ~29
  121    43      > JMP                                                      ->16
         44    >   FE_FREE                                                  $16
  137    45        INIT_FCALL                                               'array_reverse'
         46        SEND_VAR                                                 !3
         47        DO_ICALL                                         $30     
         48        ASSIGN                                                   !3, $30
  138    49        INIT_FCALL                                               'implode'
         50        SEND_VAL                                                 '+'
         51        SEND_VAR                                                 !3
         52        DO_ICALL                                         $32     
         53      > RETURN                                                   $32
  139    54*     > RETURN                                                   null

End of function numbertotext

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.4 ms | 1030 KiB | 25 Q