3v4l.org

run code in 500+ PHP versions simultaneously
<?php $input = '20-5*2/30+9='; $inputLength = mb_strlen($input); $number = 0; $result = 0; $op = ''; for ($i = 0; $i < $inputLength; $i++) { $char = mb_substr($input, $i, 1); if ($char == '*' || $char == '+' || $char == '-' || $char == '=' || $char == '/') { if ($op == '') { $result = $number; } elseif ($op == '+') { $result += $number; } elseif ($op == '-') { $result -= $number; } elseif ($op == '*') { $result *= $number; } elseif ($op == '/') { $result /= $number; } echo "op[$op] result[$result] number[$number] char[$char] \n"; $op = $char; $number = 0; if ($char == '=') { echo "Ответ: $input$result"; } } elseif (is_numeric($char) || $char == '.') { $number = $number * 10 + intval($char); } else { echo "Неверный символ:'$char\n"; exit(); } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 85
Branch analysis from position: 85
2 jumps found. (Code = 44) Position 1 = 87, Position 2 = 10
Branch analysis from position: 87
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 47) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
2 jumps found. (Code = 47) Position 1 = 21, Position 2 = 23
Branch analysis from position: 21
2 jumps found. (Code = 47) Position 1 = 24, Position 2 = 26
Branch analysis from position: 24
2 jumps found. (Code = 47) Position 1 = 27, Position 2 = 29
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 68
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 34
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 67
Branch analysis from position: 63
1 jumps found. (Code = 42) Position 1 = 84
Branch analysis from position: 84
2 jumps found. (Code = 44) Position 1 = 87, Position 2 = 10
Branch analysis from position: 87
Branch analysis from position: 10
Branch analysis from position: 67
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 38
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 42
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 46
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
Branch analysis from position: 46
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 49
Branch analysis from position: 48
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 67
Branch analysis from position: 63
Branch analysis from position: 67
Branch analysis from position: 49
Branch analysis from position: 68
2 jumps found. (Code = 47) Position 1 = 70, Position 2 = 72
Branch analysis from position: 70
2 jumps found. (Code = 43) Position 1 = 73, Position 2 = 78
Branch analysis from position: 73
1 jumps found. (Code = 42) Position 1 = 84
Branch analysis from position: 84
Branch analysis from position: 78
1 jumps found. (Code = 61) Position 1 = -2
Branch analysis from position: 72
Branch analysis from position: 29
Branch analysis from position: 26
Branch analysis from position: 23
Branch analysis from position: 20
filename:       /in/D5Apr
function name:  (null)
number of ops:  88
compiled vars:  !0 = $input, !1 = $inputLength, !2 = $number, !3 = $result, !4 = $op, !5 = $i, !6 = $char
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '20-5%2A2%2F30%2B9%3D'
    4     1        INIT_FCALL                                                   'mb_strlen'
          2        SEND_VAR                                                     !0
          3        DO_ICALL                                             $8      
          4        ASSIGN                                                       !1, $8
    5     5        ASSIGN                                                       !2, 0
    6     6        ASSIGN                                                       !3, 0
    7     7        ASSIGN                                                       !4, ''
    8     8        ASSIGN                                                       !5, 0
          9      > JMP                                                          ->85
    9    10    >   INIT_FCALL                                                   'mb_substr'
         11        SEND_VAR                                                     !0
         12        SEND_VAR                                                     !5
         13        SEND_VAL                                                     1
         14        DO_ICALL                                             $14     
         15        ASSIGN                                                       !6, $14
   10    16        IS_EQUAL                                             ~16     !6, '%2A'
         17      > JMPNZ_EX                                             ~16     ~16, ->20
         18    >   IS_EQUAL                                             ~17     !6, '%2B'
         19        BOOL                                                 ~16     ~17
         20    > > JMPNZ_EX                                             ~16     ~16, ->23
         21    >   IS_EQUAL                                             ~18     !6, '-'
         22        BOOL                                                 ~16     ~18
         23    > > JMPNZ_EX                                             ~16     ~16, ->26
         24    >   IS_EQUAL                                             ~19     !6, '%3D'
         25        BOOL                                                 ~16     ~19
         26    > > JMPNZ_EX                                             ~16     ~16, ->29
         27    >   IS_EQUAL                                             ~20     !6, '%2F'
         28        BOOL                                                 ~16     ~20
         29    > > JMPZ                                                         ~16, ->68
   11    30    >   IS_EQUAL                                                     !4, ''
         31      > JMPZ                                                         ~21, ->34
   12    32    >   ASSIGN                                                       !3, !2
   11    33      > JMP                                                          ->49
   13    34    >   IS_EQUAL                                                     !4, '%2B'
         35      > JMPZ                                                         ~23, ->38
   14    36    >   ASSIGN_OP                                         1          !3, !2
   13    37      > JMP                                                          ->49
   15    38    >   IS_EQUAL                                                     !4, '-'
         39      > JMPZ                                                         ~25, ->42
   16    40    >   ASSIGN_OP                                         2          !3, !2
   15    41      > JMP                                                          ->49
   17    42    >   IS_EQUAL                                                     !4, '%2A'
         43      > JMPZ                                                         ~27, ->46
   18    44    >   ASSIGN_OP                                         3          !3, !2
   17    45      > JMP                                                          ->49
   19    46    >   IS_EQUAL                                                     !4, '%2F'
         47      > JMPZ                                                         ~29, ->49
   20    48    >   ASSIGN_OP                                         4          !3, !2
   22    49    >   ROPE_INIT                                         9  ~32     'op%5B'
         50        ROPE_ADD                                          1  ~32     ~32, !4
         51        ROPE_ADD                                          2  ~32     ~32, '%5D+result%5B'
         52        ROPE_ADD                                          3  ~32     ~32, !3
         53        ROPE_ADD                                          4  ~32     ~32, '%5D+number%5B'
         54        ROPE_ADD                                          5  ~32     ~32, !2
         55        ROPE_ADD                                          6  ~32     ~32, '%5D+char%5B'
         56        ROPE_ADD                                          7  ~32     ~32, !6
         57        ROPE_END                                          8  ~31     ~32, '%5D+%0A'
         58        ECHO                                                         ~31
   23    59        ASSIGN                                                       !4, !6
   24    60        ASSIGN                                                       !2, 0
   25    61        IS_EQUAL                                                     !6, '%3D'
         62      > JMPZ                                                         ~39, ->67
   26    63    >   ROPE_INIT                                         3  ~41     '%D0%9E%D1%82%D0%B2%D0%B5%D1%82%3A+'
         64        ROPE_ADD                                          1  ~41     ~41, !0
         65        ROPE_END                                          2  ~40     ~41, !3
         66        ECHO                                                         ~40
   10    67    > > JMP                                                          ->84
   28    68    >   FRAMELESS_ICALL_1                is_numeric          ~43     !6
         69      > JMPNZ_EX                                             ~43     ~43, ->72
         70    >   IS_EQUAL                                             ~44     !6, '.'
         71        BOOL                                                 ~43     ~44
         72    > > JMPZ                                                         ~43, ->78
   29    73    >   MUL                                                  ~45     !2, 10
         74        CAST                                              4  ~46     !6
         75        ADD                                                  ~47     ~45, ~46
         76        ASSIGN                                                       !2, ~47
   28    77      > JMP                                                          ->84
   31    78    >   ROPE_INIT                                         3  ~50     '%D0%9D%D0%B5%D0%B2%D0%B5%D1%80%D0%BD%D1%8B%D0%B9+%D1%81%D0%B8%D0%BC%D0%B2%D0%BE%D0%BB%3A%27'
         79        ROPE_ADD                                          1  ~50     ~50, !6
         80        ROPE_END                                          2  ~49     ~50, '%0A'
         81        ECHO                                                         ~49
   32    82      > INIT_FCALL                                                   'exit'
         83*       DO_ICALL                                                     
    8    84    >   PRE_INC                                                      !5
         85    >   IS_SMALLER                                                   !5, !1
         86      > JMPNZ                                                        ~54, ->10
   34    87    > > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
162.26 ms | 2237 KiB | 16 Q