3v4l.org

run code in 300+ PHP versions simultaneously
<?php function findANeedle(string $haystack, array $needles) { foreach ($needles as $needle) { if (str_contains($haystack, $needle)) { return $needle; } } return null; } function hasANeedle(string $haystack, array $needles): bool { foreach ($needles as $needle) { if (str_contains($haystack, $needle)) { return true; } } return false; } $haystack = 'food fighters'; $needles = ['bar', 'foo']; var_export(findANeedle($haystack, $needles)); echo "\n--\n"; var_export(hasANeedle($haystack, $needles));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7LrSm
function name:  (null)
number of ops:  18
compiled vars:  !0 = $haystack, !1 = $needles
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   ASSIGN                                                   !0, 'food+fighters'
   22     1        ASSIGN                                                   !1, <array>
   24     2        INIT_FCALL                                               'var_export'
          3        INIT_FCALL                                               'findaneedle'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
   25     9        ECHO                                                     '%0A--%0A'
   26    10        INIT_FCALL                                               'var_export'
         11        INIT_FCALL                                               'hasaneedle'
         12        SEND_VAR                                                 !0
         13        SEND_VAR                                                 !1
         14        DO_FCALL                                      0  $6      
         15        SEND_VAR                                                 $6
         16        DO_ICALL                                                 
         17      > RETURN                                                   1

Function findaneedle:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 12
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 12
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/7LrSm
function name:  findANeedle
number of ops:  15
compiled vars:  !0 = $haystack, !1 = $needles, !2 = $needle
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2      > FE_RESET_R                                       $3      !1, ->12
          3    > > FE_FETCH_R                                               $3, !2, ->12
    5     4    >   INIT_FCALL                                               'str_contains'
          5        SEND_VAR                                                 !0
          6        SEND_VAR                                                 !2
          7        DO_ICALL                                         $4      
          8      > JMPZ                                                     $4, ->11
    6     9    >   FE_FREE                                                  $3
         10      > RETURN                                                   !2
    4    11    > > JMP                                                      ->3
         12    >   FE_FREE                                                  $3
    9    13      > RETURN                                                   null
   10    14*     > RETURN                                                   null

End of function findaneedle

Function hasaneedle:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 12
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 12
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/7LrSm
function name:  hasANeedle
number of ops:  16
compiled vars:  !0 = $haystack, !1 = $needles, !2 = $needle
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   13     2      > FE_RESET_R                                       $3      !1, ->12
          3    > > FE_FETCH_R                                               $3, !2, ->12
   14     4    >   INIT_FCALL                                               'str_contains'
          5        SEND_VAR                                                 !0
          6        SEND_VAR                                                 !2
          7        DO_ICALL                                         $4      
          8      > JMPZ                                                     $4, ->11
   15     9    >   FE_FREE                                                  $3
         10      > RETURN                                                   <true>
   13    11    > > JMP                                                      ->3
         12    >   FE_FREE                                                  $3
   18    13      > RETURN                                                   <false>
   19    14*       VERIFY_RETURN_TYPE                                       
         15*     > RETURN                                                   null

End of function hasaneedle

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
178.53 ms | 1008 KiB | 17 Q