3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array( 'green' => 'keyword', 'orange', 'keyword', 'black' => array( 'purple' => 'text', 'brown', 'pink' => 'keyword' ), 'white' => array( 'red', 'yellow' => 'keyword', 'blue' ), 'violet', 'gray' ); $arr = array(); $str = 'keyword'; $arr[] = array_filter($array, function($var) use ($str) { global $arr; if(is_array($var)){ $arr[] = array_filter($var, function($var2) use ($str) { return preg_match("/$str/i", $var2); }); }else{ return preg_match("/$str/i", $var); } }); function getL2Keys($array){ $result = array(); foreach($array as $sub) { $result = array_merge($result, $sub); } return $result; } $arr = getL2Keys($arr); echo '<pre>'; print_r($arr);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aCQFt
function name:  (null)
number of ops:  20
compiled vars:  !0 = $array, !1 = $arr, !2 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   20     1        ASSIGN                                                   !1, <array>
   22     2        ASSIGN                                                   !2, 'keyword'
   23     3        INIT_FCALL                                               'array_filter'
          4        SEND_VAR                                                 !0
          5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FaCQFt%3A23%240'
          6        BIND_LEXICAL                                             ~7, !2
   32     7        SEND_VAL                                                 ~7
          8        DO_ICALL                                         $8      
   23     9        ASSIGN_DIM                                               !1
   32    10        OP_DATA                                                  $8
   42    11        INIT_FCALL                                               'getl2keys'
         12        SEND_VAR                                                 !1
         13        DO_FCALL                                      0  $9      
         14        ASSIGN                                                   !1, $9
   43    15        ECHO                                                     '%3Cpre%3E'
   44    16        INIT_FCALL                                               'print_r'
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                                 
         19      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FaCQFt%3A23%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 14
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aCQFt
function name:  {closure}
number of ops:  23
compiled vars:  !0 = $var, !1 = $str, !2 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   24     2        BIND_GLOBAL                                              !2, 'arr'
   25     3        TYPE_CHECK                                  128          !0
          4      > JMPZ                                                     ~3, ->14
   26     5    >   INIT_FCALL                                               'array_filter'
          6        SEND_VAR                                                 !0
          7        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FaCQFt%3A26%241'
          8        BIND_LEXICAL                                             ~5, !1
   28     9        SEND_VAL                                                 ~5
         10        DO_ICALL                                         $6      
   26    11        ASSIGN_DIM                                               !2
   28    12        OP_DATA                                                  $6
         13      > JMP                                                      ->22
   30    14    >   INIT_FCALL                                               'preg_match'
         15        ROPE_INIT                                     3  ~8      '%2F'
         16        ROPE_ADD                                      1  ~8      ~8, !1
         17        ROPE_END                                      2  ~7      ~8, '%2Fi'
         18        SEND_VAL                                                 ~7
         19        SEND_VAR                                                 !0
         20        DO_ICALL                                         $10     
         21      > RETURN                                                   $10
   32    22    > > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FaCQFt%3A23%240

Function %00%7Bclosure%7D%2Fin%2FaCQFt%3A26%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aCQFt
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $var2, !1 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   27     2        INIT_FCALL                                               'preg_match'
          3        ROPE_INIT                                     3  ~3      '%2F'
          4        ROPE_ADD                                      1  ~3      ~3, !1
          5        ROPE_END                                      2  ~2      ~3, '%2Fi'
          6        SEND_VAL                                                 ~2
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $5      
          9      > RETURN                                                   $5
   28    10*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FaCQFt%3A26%241

Function getl2keys:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 10
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/aCQFt
function name:  getL2Keys
number of ops:  13
compiled vars:  !0 = $array, !1 = $result, !2 = $sub
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
   35     1        ASSIGN                                                   !1, <array>
   36     2      > FE_RESET_R                                       $4      !0, ->10
          3    > > FE_FETCH_R                                               $4, !2, ->10
   37     4    >   INIT_FCALL                                               'array_merge'
          5        SEND_VAR                                                 !1
          6        SEND_VAR                                                 !2
          7        DO_ICALL                                         $5      
          8        ASSIGN                                                   !1, $5
   36     9      > JMP                                                      ->3
         10    >   FE_FREE                                                  $4
   39    11      > RETURN                                                   !1
   40    12*     > RETURN                                                   null

End of function getl2keys

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
181.75 ms | 1407 KiB | 22 Q