3v4l.org

run code in 500+ PHP versions simultaneously
<?php $results = array( 0 => 'DogCatSheepBlue WhaleShark', 1 => 'CatPigGoatOtter', 2 => 'ElephantTigerDogBlue WhaleGoat', 3 => 'SeahorseSnakeGoatLion' ); function search($array, $search) { $words = explode(' ', $search); $regex = '/(' . implode('|', array_filter($words)) . ')/'; return array_filter($array, function ($v) use ($regex) { return preg_match($regex, $v); }); } print_r(search($results, 'Cat Whale')); print_r(search($results, 'GoatSeahorse')); print_r(search($results, 'Pig'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/v5tjG
function name:  (null)
number of ops:  23
compiled vars:  !0 = $results
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   16     1        INIT_FCALL                                                   'print_r'
          2        INIT_FCALL                                                   'search'
          3        SEND_VAR                                                     !0
          4        SEND_VAL                                                     'Cat++++Whale'
          5        DO_FCALL                                          0  $2      
          6        SEND_VAR                                                     $2
          7        DO_ICALL                                                     
   17     8        INIT_FCALL                                                   'print_r'
          9        INIT_FCALL                                                   'search'
         10        SEND_VAR                                                     !0
         11        SEND_VAL                                                     'GoatSeahorse'
         12        DO_FCALL                                          0  $4      
         13        SEND_VAR                                                     $4
         14        DO_ICALL                                                     
   18    15        INIT_FCALL                                                   'print_r'
         16        INIT_FCALL                                                   'search'
         17        SEND_VAR                                                     !0
         18        SEND_VAL                                                     'Pig'
         19        DO_FCALL                                          0  $6      
         20        SEND_VAR                                                     $6
         21        DO_ICALL                                                     
         22      > RETURN                                                       1

Function search:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/v5tjG
function name:  search
number of ops:  22
compiled vars:  !0 = $array, !1 = $search, !2 = $words, !3 = $regex
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   10     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   11     2        INIT_FCALL                                                   'explode'
          3        SEND_VAL                                                     '+'
          4        SEND_VAR                                                     !1
          5        DO_ICALL                                             $4      
          6        ASSIGN                                                       !2, $4
   12     7        INIT_FCALL                                                   'array_filter'
          8        SEND_VAR                                                     !2
          9        DO_ICALL                                             $6      
         10        FRAMELESS_ICALL_2                implode             ~7      '%7C', $6
         11        CONCAT                                               ~8      '%2F%28', ~7
         12        CONCAT                                               ~9      ~8, '%29%2F'
         13        ASSIGN                                                       !3, ~9
   13    14        INIT_FCALL                                                   'array_filter'
         15        SEND_VAR                                                     !0
         16        DECLARE_LAMBDA_FUNCTION                              ~11     [0]
         17        BIND_LEXICAL                                                 ~11, !3
         18        SEND_VAL                                                     ~11
         19        DO_ICALL                                             $12     
         20      > RETURN                                                       $12
   14    21*     > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/v5tjG
function name:  {closure:search():13}
number of ops:  5
compiled vars:  !0 = $v, !1 = $regex
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   13     0  E >   RECV                                                 !0      
          1        BIND_STATIC                                                  !1
          2        FRAMELESS_ICALL_2                preg_match          ~2      !1, !0
          3      > RETURN                                                       ~2
          4*     > RETURN                                                       null

End of Dynamic Function 0

End of function search

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
158.16 ms | 2168 KiB | 19 Q