3v4l.org

run code in 300+ PHP versions simultaneously
<?php $expression = "-11+3*1*4/-6-12"; if (!preg_match('~^-?\d*\.?\d+([*/+-]-?\d*\.?\d+)*$~', $expression)) { echo "invalid expression"; } else { $components = preg_split('~(?<=\d)([*/+-])~', $expression, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); var_export($components); // ['-11','+','3','*','1','*','4','/','-6','-','12'] while (($index = array_search('*',$components)) !== false) { array_splice($components, $index - 1, 3, $components[$index - 1] * $components[$index + 1]); var_export($components); // ['-11','+','3','*','4','/','-6','-','12'] // ['-11','+','12','/','-6','-','12'] } while (($index = array_search('/', $components)) !== false) { array_splice($components, $index - 1, 3, $components[$index - 1] / $components[$index + 1]); var_export($components); // [-'11','+','-2','-','12'] } while (($index = array_search('+', $components)) !== false) { array_splice($components, $index - 1, 3, $components[$index - 1] + $components[$index + 1]); var_export($components); // ['-13','-','12'] } while (($index = array_search('-', $components)) !== false) { array_splice($components, $index - 1, 3, $components[$index - 1] - $components[$index + 1]); var_export($components); // [-25] } echo current($components); // -25 }
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 = 42) Position 1 = 115
Branch analysis from position: 115
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 20
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 58
Branch analysis from position: 58
2 jumps found. (Code = 44) Position 1 = 65, Position 2 = 43
Branch analysis from position: 65
1 jumps found. (Code = 42) Position 1 = 81
Branch analysis from position: 81
2 jumps found. (Code = 44) Position 1 = 88, Position 2 = 66
Branch analysis from position: 88
1 jumps found. (Code = 42) Position 1 = 104
Branch analysis from position: 104
2 jumps found. (Code = 44) Position 1 = 111, Position 2 = 89
Branch analysis from position: 111
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 89
2 jumps found. (Code = 44) Position 1 = 111, Position 2 = 89
Branch analysis from position: 111
Branch analysis from position: 89
Branch analysis from position: 66
2 jumps found. (Code = 44) Position 1 = 88, Position 2 = 66
Branch analysis from position: 88
Branch analysis from position: 66
Branch analysis from position: 43
2 jumps found. (Code = 44) Position 1 = 65, Position 2 = 43
Branch analysis from position: 65
Branch analysis from position: 43
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 20
Branch analysis from position: 42
Branch analysis from position: 20
filename:       /in/aDNbo
function name:  (null)
number of ops:  116
compiled vars:  !0 = $expression, !1 = $components, !2 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '-11%2B3%2A1%2A4%2F-6-12'
    4     1        INIT_FCALL                                               'preg_match'
          2        SEND_VAL                                                 '%7E%5E-%3F%5Cd%2A%5C.%3F%5Cd%2B%28%5B%2A%2F%2B-%5D-%3F%5Cd%2A%5C.%3F%5Cd%2B%29%2A%24%7E'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $4      
          5        BOOL_NOT                                         ~5      $4
          6      > JMPZ                                                     ~5, ->9
    5     7    >   ECHO                                                     'invalid+expression'
          8      > JMP                                                      ->115
    7     9    >   INIT_FCALL                                               'preg_split'
         10        SEND_VAL                                                 '%7E%28%3F%3C%3D%5Cd%29%28%5B%2A%2F%2B-%5D%29%7E'
         11        SEND_VAR                                                 !0
         12        SEND_VAL                                                 0
         13        SEND_VAL                                                 3
         14        DO_ICALL                                         $6      
         15        ASSIGN                                                   !1, $6
    8    16        INIT_FCALL                                               'var_export'
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                                 
    9    19      > JMP                                                      ->35
   10    20    >   INIT_FCALL                                               'array_splice'
         21        SEND_REF                                                 !1
         22        SUB                                              ~9      !2, 1
         23        SEND_VAL                                                 ~9
         24        SEND_VAL                                                 3
         25        SUB                                              ~10     !2, 1
         26        FETCH_DIM_R                                      ~11     !1, ~10
         27        ADD                                              ~12     !2, 1
         28        FETCH_DIM_R                                      ~13     !1, ~12
         29        MUL                                              ~14     ~11, ~13
         30        SEND_VAL                                                 ~14
         31        DO_ICALL                                                 
   11    32        INIT_FCALL                                               'var_export'
         33        SEND_VAR                                                 !1
         34        DO_ICALL                                                 
    9    35    >   INIT_FCALL                                               'array_search'
         36        SEND_VAL                                                 '%2A'
         37        SEND_VAR                                                 !1
         38        DO_ICALL                                         $17     
         39        ASSIGN                                           ~18     !2, $17
         40        TYPE_CHECK                                  1018          ~18
         41      > JMPNZ                                                    ~19, ->20
   15    42    > > JMP                                                      ->58
   16    43    >   INIT_FCALL                                               'array_splice'
         44        SEND_REF                                                 !1
         45        SUB                                              ~20     !2, 1
         46        SEND_VAL                                                 ~20
         47        SEND_VAL                                                 3
         48        SUB                                              ~21     !2, 1
         49        FETCH_DIM_R                                      ~22     !1, ~21
         50        ADD                                              ~23     !2, 1
         51        FETCH_DIM_R                                      ~24     !1, ~23
         52        DIV                                              ~25     ~22, ~24
         53        SEND_VAL                                                 ~25
         54        DO_ICALL                                                 
   17    55        INIT_FCALL                                               'var_export'
         56        SEND_VAR                                                 !1
         57        DO_ICALL                                                 
   15    58    >   INIT_FCALL                                               'array_search'
         59        SEND_VAL                                                 '%2F'
         60        SEND_VAR                                                 !1
         61        DO_ICALL                                         $28     
         62        ASSIGN                                           ~29     !2, $28
         63        TYPE_CHECK                                  1018          ~29
         64      > JMPNZ                                                    ~30, ->43
   19    65    > > JMP                                                      ->81
   20    66    >   INIT_FCALL                                               'array_splice'
         67        SEND_REF                                                 !1
         68        SUB                                              ~31     !2, 1
         69        SEND_VAL                                                 ~31
         70        SEND_VAL                                                 3
         71        SUB                                              ~32     !2, 1
         72        FETCH_DIM_R                                      ~33     !1, ~32
         73        ADD                                              ~34     !2, 1
         74        FETCH_DIM_R                                      ~35     !1, ~34
         75        ADD                                              ~36     ~33, ~35
         76        SEND_VAL                                                 ~36
         77        DO_ICALL                                                 
   21    78        INIT_FCALL                                               'var_export'
         79        SEND_VAR                                                 !1
         80        DO_ICALL                                                 
   19    81    >   INIT_FCALL                                               'array_search'
         82        SEND_VAL                                                 '%2B'
         83        SEND_VAR                                                 !1
         84        DO_ICALL                                         $39     
         85        ASSIGN                                           ~40     !2, $39
         86        TYPE_CHECK                                  1018          ~40
         87      > JMPNZ                                                    ~41, ->66
   23    88    > > JMP                                                      ->104
   24    89    >   INIT_FCALL                                               'array_splice'
         90        SEND_REF                                                 !1
         91        SUB                                              ~42     !2, 1
         92        SEND_VAL                                                 ~42
         93        SEND_VAL                                                 3
         94        SUB                                              ~43     !2, 1
         95        FETCH_DIM_R                                      ~44     !1, ~43
         96        ADD                                              ~45     !2, 1
         97        FETCH_DIM_R                                      ~46     !1, ~45
         98        SUB                                              ~47     ~44, ~46
         99        SEND_VAL                                                 ~47
        100        DO_ICALL                                                 
   25   101        INIT_FCALL                                               'var_export'
        102        SEND_VAR                                                 !1
        103        DO_ICALL                                                 
   23   104    >   INIT_FCALL                                               'array_search'
        105        SEND_VAL                                                 '-'
        106        SEND_VAR                                                 !1
        107        DO_ICALL                                         $50     
        108        ASSIGN                                           ~51     !2, $50
        109        TYPE_CHECK                                  1018          ~51
        110      > JMPNZ                                                    ~52, ->89
   27   111    >   INIT_FCALL                                               'current'
        112        SEND_VAR                                                 !1
        113        DO_ICALL                                         $53     
        114        ECHO                                                     $53
   28   115    > > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.83 ms | 1404 KiB | 25 Q