3v4l.org

run code in 500+ 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 = 4, Position 2 = 5
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 11
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 14
Branch analysis from position: 13
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 = 43) Position 1 = 18, Position 2 = 19
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
Branch analysis from position: 11
Branch analysis from position: 8
Branch analysis from position: 5
filename:       /in/YqtZG
function name:  getCode
number of ops:  21
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        FRAMELESS_ICALL_2                preg_match          ~3      '%2F%5Cbred%5Cb%2Fi', !0
          3      > JMPZ                                                         ~3, ->5
    6     4    >   ASSIGN_OP                                         1          !1, 2
    8     5    >   FRAMELESS_ICALL_2                preg_match          ~5      '%2F%5Cbblue%5Cb%2Fi', !0
          6      > JMPZ                                                         ~5, ->8
    9     7    >   ASSIGN_OP                                         1          !1, 3
   11     8    >   FRAMELESS_ICALL_2                preg_match          ~7      '%2F%5Cbgreen%5Cb%2Fi', !0
          9      > JMPZ                                                         ~7, ->11
   12    10    >   ASSIGN_OP                                         1          !1, 4
   14    11    >   IS_IDENTICAL                                                 !1, 9
         12      > JMPZ                                                         ~9, ->14
   15    13    >   ASSIGN_OP                                         1          !1, 2
   17    14    > > JMPZ                                                         !1, ->16
   18    15    > > RETURN                                                       !1
   20    16    >   FRAMELESS_ICALL_2                preg_match          ~11     '%2F%5Cbballoon%5Cb%2Fi', !0
         17      > JMPZ                                                         ~11, ->19
   21    18    > > RETURN                                                       1
   23    19    > > RETURN                                                       0
   24    20*     > RETURN                                                       null

End of function getcode

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
178.76 ms | 1949 KiB | 15 Q