3v4l.org

run code in 300+ PHP versions simultaneously
<?php function num2str($num) { $nul='ноль'; $ten=array( array('','один','два','три','четыре','пять','шесть','семь', 'восемь','девять'), array('','одна','две','три','четыре','пять','шесть','семь', 'восемь','девять'), ); $a20=array('десять','одиннадцать','двенадцать','тринадцать','четырнадцать' ,'пятнадцать','шестнадцать','семнадцать','восемнадцать','девятнадцать'); $tens=array(2=>'двадцать','тридцать','сорок','пятьдесят','шестьдесят','семьдесят' ,'восемьдесят','девяносто'); $hundred=array('','сто','двести','триста','четыреста','пятьсот','шестьсот', 'семьсот','восемьсот','девятьсот'); $unit=array( // Units array('копейка' ,'копейки' ,'копеек', 1), array('рубль' ,'рубля' ,'рублей' ,0), array('тысяча' ,'тысячи' ,'тысяч' ,1), array('миллион' ,'миллиона','миллионов' ,0), array('миллиард','милиарда','миллиардов',0), ); // list($rub,$kop) = explode('.',sprintf("%015.2f", floatval($num))); $out = array(); if (intval($rub)>0) { foreach(str_split($rub,3) as $uk=>$v) { // by 3 symbols if (!intval($v)) continue; $uk = sizeof($unit)-$uk-1; // unit key $gender = $unit[$uk][3]; list($i1,$i2,$i3) = array_map('intval',str_split($v,1)); // mega-logic $out[] = $hundred[$i1]; # 1xx-9xx if ($i2>1) $out[]= $tens[$i2].' '.$ten[$gender][$i3]; # 20-99 else $out[]= $i2>0 ? $a20[$i3] : $ten[$gender][$i3]; # 10-19 | 1-9 // units without rub & kop if ($uk>1) $out[]= morph($v,$unit[$uk][0],$unit[$uk][1],$unit[$uk][2]); } //foreach } else $out[] = $nul; $out[] = morph(intval($rub), $unit[1][0],$unit[1][1],$unit[1][2]); // rub $out[] = $kop.' '.morph($kop,$unit[0][0],$unit[0][1],$unit[0][2]); // kop return trim(preg_replace('/ {2,}/', ' ', join(' ',$out))); } /** * Склоняем словоформу * @ author runcore */ function morph($n, $f1, $f2, $f5) { $n = abs(intval($n)) % 100; if ($n>10 && $n<20) return $f5; $n = $n % 10; if ($n>1 && $n<5) return $f2; if ($n==1) return $f1; return $f5; } $x = "100001001"; echo num2str($x);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/U5drS
function name:  (null)
number of ops:  6
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   ASSIGN                                                   !0, '100001001'
   54     1        INIT_FCALL                                               'num2str'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $2      
          4        ECHO                                                     $2
          5      > RETURN                                                   1

Function num2str:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 103
Branch analysis from position: 25
2 jumps found. (Code = 77) Position 1 = 30, Position 2 = 101
Branch analysis from position: 30
2 jumps found. (Code = 78) Position 1 = 31, Position 2 = 101
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 36
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 71
Branch analysis from position: 63
1 jumps found. (Code = 42) Position 1 = 81
Branch analysis from position: 81
2 jumps found. (Code = 43) Position 1 = 83, Position 2 = 100
Branch analysis from position: 83
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 100
Branch analysis from position: 71
2 jumps found. (Code = 43) Position 1 = 73, Position 2 = 76
Branch analysis from position: 73
1 jumps found. (Code = 42) Position 1 = 79
Branch analysis from position: 79
2 jumps found. (Code = 43) Position 1 = 83, Position 2 = 100
Branch analysis from position: 83
Branch analysis from position: 100
Branch analysis from position: 76
2 jumps found. (Code = 43) Position 1 = 83, Position 2 = 100
Branch analysis from position: 83
Branch analysis from position: 100
Branch analysis from position: 101
1 jumps found. (Code = 42) Position 1 = 105
Branch analysis from position: 105
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 101
Branch analysis from position: 103
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/U5drS
function name:  num2str
number of ops:  156
compiled vars:  !0 = $num, !1 = $nul, !2 = $ten, !3 = $a20, !4 = $tens, !5 = $hundred, !6 = $unit, !7 = $rub, !8 = $kop, !9 = $out, !10 = $v, !11 = $uk, !12 = $gender, !13 = $i1, !14 = $i2, !15 = $i3
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        ASSIGN                                                   !1, '%D0%BD%D0%BE%D0%BB%D1%8C'
    4     2        ASSIGN                                                   !2, <array>
    8     3        ASSIGN                                                   !3, <array>
    9     4        ASSIGN                                                   !4, <array>
   10     5        ASSIGN                                                   !5, <array>
   11     6        ASSIGN                                                   !6, <array>
   19     7        INIT_FCALL                                               'explode'
          8        SEND_VAL                                                 '.'
          9        INIT_FCALL                                               'sprintf'
         10        SEND_VAL                                                 '%25015.2f'
         11        CAST                                          5  ~22     !0
         12        SEND_VAL                                                 ~22
         13        DO_ICALL                                         $23     
         14        SEND_VAR                                                 $23
         15        DO_ICALL                                         $24     
         16        FETCH_LIST_R                                     $25     $24, 0
         17        ASSIGN                                                   !7, $25
         18        FETCH_LIST_R                                     $27     $24, 1
         19        ASSIGN                                                   !8, $27
         20        FREE                                                     $24
   20    21        ASSIGN                                                   !9, <array>
   21    22        CAST                                          4  ~30     !7
         23        IS_SMALLER                                               0, ~30
         24      > JMPZ                                                     ~31, ->103
   22    25    >   INIT_FCALL                                               'str_split'
         26        SEND_VAR                                                 !7
         27        SEND_VAL                                                 3
         28        DO_ICALL                                         $32     
         29      > FE_RESET_R                                       $33     $32, ->101
         30    > > FE_FETCH_R                                       ~34     $33, !10, ->101
         31    >   ASSIGN                                                   !11, ~34
   23    32        CAST                                          4  ~36     !10
         33        BOOL_NOT                                         ~37     ~36
         34      > JMPZ                                                     ~37, ->36
         35    > > JMP                                                      ->30
   24    36    >   COUNT                                            ~38     !6
         37        SUB                                              ~39     ~38, !11
         38        SUB                                              ~40     ~39, 1
         39        ASSIGN                                                   !11, ~40
   25    40        FETCH_DIM_R                                      ~42     !6, !11
         41        FETCH_DIM_R                                      ~43     ~42, 3
         42        ASSIGN                                                   !12, ~43
   26    43        INIT_FCALL                                               'array_map'
         44        SEND_VAL                                                 'intval'
         45        INIT_FCALL                                               'str_split'
         46        SEND_VAR                                                 !10
         47        SEND_VAL                                                 1
         48        DO_ICALL                                         $45     
         49        SEND_VAR                                                 $45
         50        DO_ICALL                                         $46     
         51        FETCH_LIST_R                                     $47     $46, 0
         52        ASSIGN                                                   !13, $47
         53        FETCH_LIST_R                                     $49     $46, 1
         54        ASSIGN                                                   !14, $49
         55        FETCH_LIST_R                                     $51     $46, 2
         56        ASSIGN                                                   !15, $51
         57        FREE                                                     $46
   28    58        FETCH_DIM_R                                      ~54     !5, !13
         59        ASSIGN_DIM                                               !9
         60        OP_DATA                                                  ~54
   29    61        IS_SMALLER                                               1, !14
         62      > JMPZ                                                     ~55, ->71
         63    >   FETCH_DIM_R                                      ~57     !4, !14
         64        CONCAT                                           ~58     ~57, '+'
         65        FETCH_DIM_R                                      ~59     !2, !12
         66        FETCH_DIM_R                                      ~60     ~59, !15
         67        CONCAT                                           ~61     ~58, ~60
         68        ASSIGN_DIM                                               !9
         69        OP_DATA                                                  ~61
         70      > JMP                                                      ->81
   30    71    >   IS_SMALLER                                               0, !14
         72      > JMPZ                                                     ~63, ->76
         73    >   FETCH_DIM_R                                      ~64     !3, !15
         74        QM_ASSIGN                                        ~65     ~64
         75      > JMP                                                      ->79
         76    >   FETCH_DIM_R                                      ~66     !2, !12
         77        FETCH_DIM_R                                      ~67     ~66, !15
         78        QM_ASSIGN                                        ~65     ~67
         79    >   ASSIGN_DIM                                               !9
         80        OP_DATA                                                  ~65
   32    81    >   IS_SMALLER                                               1, !11
         82      > JMPZ                                                     ~68, ->100
         83    >   INIT_FCALL_BY_NAME                                       'morph'
         84        SEND_VAR_EX                                              !10
         85        CHECK_FUNC_ARG                                           
         86        FETCH_DIM_FUNC_ARG                               $70     !6, !11
         87        FETCH_DIM_FUNC_ARG                               $71     $70, 0
         88        SEND_FUNC_ARG                                            $71
         89        CHECK_FUNC_ARG                                           
         90        FETCH_DIM_FUNC_ARG                               $72     !6, !11
         91        FETCH_DIM_FUNC_ARG                               $73     $72, 1
         92        SEND_FUNC_ARG                                            $73
         93        CHECK_FUNC_ARG                                           
         94        FETCH_DIM_FUNC_ARG                               $74     !6, !11
         95        FETCH_DIM_FUNC_ARG                               $75     $74, 2
         96        SEND_FUNC_ARG                                            $75
         97        DO_FCALL                                      0  $76     
         98        ASSIGN_DIM                                               !9
         99        OP_DATA                                                  $76
   22   100    > > JMP                                                      ->30
        101    >   FE_FREE                                                  $33
        102      > JMP                                                      ->105
   35   103    >   ASSIGN_DIM                                               !9
        104        OP_DATA                                                  !1
   36   105    >   INIT_FCALL_BY_NAME                                       'morph'
        106        CAST                                          4  ~79     !7
        107        SEND_VAL_EX                                              ~79
        108        CHECK_FUNC_ARG                                           
        109        FETCH_DIM_FUNC_ARG                               $80     !6, 1
        110        FETCH_DIM_FUNC_ARG                               $81     $80, 0
        111        SEND_FUNC_ARG                                            $81
        112        CHECK_FUNC_ARG                                           
        113        FETCH_DIM_FUNC_ARG                               $82     !6, 1
        114        FETCH_DIM_FUNC_ARG                               $83     $82, 1
        115        SEND_FUNC_ARG                                            $83
        116        CHECK_FUNC_ARG                                           
        117        FETCH_DIM_FUNC_ARG                               $84     !6, 1
        118        FETCH_DIM_FUNC_ARG                               $85     $84, 2
        119        SEND_FUNC_ARG                                            $85
        120        DO_FCALL                                      0  $86     
        121        ASSIGN_DIM                                               !9
        122        OP_DATA                                                  $86
   37   123        CONCAT                                           ~88     !8, '+'
        124        INIT_FCALL_BY_NAME                                       'morph'
        125        SEND_VAR_EX                                              !8
        126        CHECK_FUNC_ARG                                           
        127        FETCH_DIM_FUNC_ARG                               $89     !6, 0
        128        FETCH_DIM_FUNC_ARG                               $90     $89, 0
        129        SEND_FUNC_ARG                                            $90
        130        CHECK_FUNC_ARG                                           
        131        FETCH_DIM_FUNC_ARG                               $91     !6, 0
        132        FETCH_DIM_FUNC_ARG                               $92     $91, 1
        133        SEND_FUNC_ARG                                            $92
        134        CHECK_FUNC_ARG                                           
        135        FETCH_DIM_FUNC_ARG                               $93     !6, 0
        136        FETCH_DIM_FUNC_ARG                               $94     $93, 2
        137        SEND_FUNC_ARG                                            $94
        138        DO_FCALL                                      0  $95     
        139        CONCAT                                           ~96     ~88, $95
        140        ASSIGN_DIM                                               !9
        141        OP_DATA                                                  ~96
   38   142        INIT_FCALL                                               'trim'
        143        INIT_FCALL                                               'preg_replace'
        144        SEND_VAL                                                 '%2F+%7B2%2C%7D%2F'
        145        SEND_VAL                                                 '+'
        146        INIT_FCALL                                               'join'
        147        SEND_VAL                                                 '+'
        148        SEND_VAR                                                 !9
        149        DO_ICALL                                         $97     
        150        SEND_VAR                                                 $97
        151        DO_ICALL                                         $98     
        152        SEND_VAR                                                 $98
        153        DO_ICALL                                         $99     
        154      > RETURN                                                   $99
   39   155*     > RETURN                                                   null

End of function num2str

Function morph:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
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 = 62) Position 1 = -2
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 27
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
Branch analysis from position: 14
filename:       /in/U5drS
function name:  morph
number of ops:  29
compiled vars:  !0 = $n, !1 = $f1, !2 = $f2, !3 = $f5
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   46     4        INIT_FCALL                                               'abs'
          5        CAST                                          4  ~4      !0
          6        SEND_VAL                                                 ~4
          7        DO_ICALL                                         $5      
          8        MOD                                              ~6      $5, 100
          9        ASSIGN                                                   !0, ~6
   47    10        IS_SMALLER                                       ~8      10, !0
         11      > JMPZ_EX                                          ~8      ~8, ->14
         12    >   IS_SMALLER                                       ~9      !0, 20
         13        BOOL                                             ~8      ~9
         14    > > JMPZ                                                     ~8, ->16
         15    > > RETURN                                                   !3
   48    16    >   MOD                                              ~10     !0, 10
         17        ASSIGN                                                   !0, ~10
   49    18        IS_SMALLER                                       ~12     1, !0
         19      > JMPZ_EX                                          ~12     ~12, ->22
         20    >   IS_SMALLER                                       ~13     !0, 5
         21        BOOL                                             ~12     ~13
         22    > > JMPZ                                                     ~12, ->24
         23    > > RETURN                                                   !2
   50    24    >   IS_EQUAL                                                 !0, 1
         25      > JMPZ                                                     ~14, ->27
         26    > > RETURN                                                   !1
   51    27    > > RETURN                                                   !3
   52    28*     > RETURN                                                   null

End of function morph

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
183.69 ms | 1415 KiB | 30 Q