3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getCode($string) { $code = 0; if (preg_match('/\bred\b/i', $string)) { $code += 2; } if (preg_match('/\bblue\b/i', $string)) { $code += 3; } if (preg_match('/\bgreen\b/i', $string)) { $code += 4; } if ($code === 9) { $code += 2; } if ($code) { return $code; } if (preg_match('/\bballoon\b/i', $string)) { return 1; } return 0; } $sentences = [ 'Here is a green, blue, and red balloon', 'A blue balloon here', 'A red herring', 'Blue is the name of my dog', 'Red and green are Xmas colors', 'blue skies over green grass', 'Foo is bar', 'Have a balloon and a balloon and a balloon', 'A green balloon', 'A blue balloon with a red string', ]; foreach ($sentences as $sentence) { printf("%s => %d\n", $sentence, getCode($sentence)); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 12
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 12
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/YqtZG
function name:  (null)
number of ops:  14
compiled vars:  !0 = $sentences, !1 = $sentence
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   ASSIGN                                                   !0, <array>
   39     1      > FE_RESET_R                                       $3      !0, ->12
          2    > > FE_FETCH_R                                               $3, !1, ->12
   40     3    >   INIT_FCALL                                               'printf'
          4        SEND_VAL                                                 '%25s+%3D%3E+%25d%0A'
          5        SEND_VAR                                                 !1
          6        INIT_FCALL                                               'getcode'
          7        SEND_VAR                                                 !1
          8        DO_FCALL                                      0  $4      
          9        SEND_VAR                                                 $4
         10        DO_ICALL                                                 
   39    11      > JMP                                                      ->2
         12    >   FE_FREE                                                  $3
   41    13      > RETURN                                                   1

Function getcode:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 14
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 20
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 23
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 25
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 31
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
Branch analysis from position: 20
Branch analysis from position: 14
Branch analysis from position: 8
filename:       /in/YqtZG
function name:  getCode
number of ops:  33
compiled vars:  !0 = $string, !1 = $code
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, 0
    5     2        INIT_FCALL                                               'preg_match'
          3        SEND_VAL                                                 '%2F%5Cbred%5Cb%2Fi'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $3      
          6      > JMPZ                                                     $3, ->8
    6     7    >   ASSIGN_OP                                     1          !1, 2
    8     8    >   INIT_FCALL                                               'preg_match'
          9        SEND_VAL                                                 '%2F%5Cbblue%5Cb%2Fi'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $5      
         12      > JMPZ                                                     $5, ->14
    9    13    >   ASSIGN_OP                                     1          !1, 3
   11    14    >   INIT_FCALL                                               'preg_match'
         15        SEND_VAL                                                 '%2F%5Cbgreen%5Cb%2Fi'
         16        SEND_VAR                                                 !0
         17        DO_ICALL                                         $7      
         18      > JMPZ                                                     $7, ->20
   12    19    >   ASSIGN_OP                                     1          !1, 4
   14    20    >   IS_IDENTICAL                                             !1, 9
         21      > JMPZ                                                     ~9, ->23
   15    22    >   ASSIGN_OP                                     1          !1, 2
   17    23    > > JMPZ                                                     !1, ->25
   18    24    > > RETURN                                                   !1
   20    25    >   INIT_FCALL                                               'preg_match'
         26        SEND_VAL                                                 '%2F%5Cbballoon%5Cb%2Fi'
         27        SEND_VAR                                                 !0
         28        DO_ICALL                                         $11     
         29      > JMPZ                                                     $11, ->31
   21    30    > > RETURN                                                   1
   23    31    > > RETURN                                                   0
   24    32*     > RETURN                                                   null

End of function getcode

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.04 ms | 1018 KiB | 16 Q