3v4l.org

run code in 300+ 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:  25
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                                               'implode'
          8        SEND_VAL                                                 '%7C'
          9        INIT_FCALL                                               'array_filter'
         10        SEND_VAR                                                 !2
         11        DO_ICALL                                         $6      
         12        SEND_VAR                                                 $6
         13        DO_ICALL                                         $7      
         14        CONCAT                                           ~8      '%2F%28', $7
         15        CONCAT                                           ~9      ~8, '%29%2F'
         16        ASSIGN                                                   !3, ~9
   13    17        INIT_FCALL                                               'array_filter'
         18        SEND_VAR                                                 !0
         19        DECLARE_LAMBDA_FUNCTION                          ~11     [0]
         20        BIND_LEXICAL                                             ~11, !3
         21        SEND_VAL                                                 ~11
         22        DO_ICALL                                         $12     
         23      > RETURN                                                   $12
   14    24*     > 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}
number of ops:  8
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        INIT_FCALL                                               'preg_match'
          3        SEND_VAR                                                 !1
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
          6      > RETURN                                                   $2
          7*     > RETURN                                                   null

End of Dynamic Function 0

End of function search

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
229.68 ms | 1014 KiB | 21 Q