3v4l.org

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

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
234.78 ms | 2133 KiB | 18 Q