3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ArrayFilters { private $array = array(); private $name; public function __construct($array, $name){ $this->array = $array; $this->name = $name; } public function name_is($arr){ return $arr['name'] == $this->name; } } $array1 = array( "a"=>array( 'name' => 'vasya' ,'second_name' => 'Vasilev' ), "b"=>array( 'name' => 'vasya2' ,'second_name' => 'Vasilev2' ), "c"=>array( 'name' => 'vasya3' ,'second_name' => 'Vasilev3' ), "d"=>array( 'name' => 'vasya4' ,'second_name' => 'Vasilev4' ), "e"=>array( 'name' => 'vasya5' ,'second_name' => 'Vasilev5' ) ); $name = 'vasya2'; //print_r(array_filter($array1, array(new ArrayFilters($array1, 'vasya2'), 'name_is'))); print_r( array_filter( $array1, function($value, $ok = '1') use ($name) { echo $ok; return $value['name'] == $name; } ) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PPIkq
function name:  (null)
number of ops:  12
compiled vars:  !0 = $array1, !1 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   ASSIGN                                                   !0, <array>
   40     1        ASSIGN                                                   !1, 'vasya2'
   42     2        INIT_FCALL                                               'print_r'
   43     3        INIT_FCALL                                               'array_filter'
   44     4        SEND_VAR                                                 !0
   45     5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FPPIkq%3A45%240'
          6        BIND_LEXICAL                                             ~4, !1
   48     7        SEND_VAL                                                 ~4
          8        DO_ICALL                                         $5      
          9        SEND_VAR                                                 $5
         10        DO_ICALL                                                 
   50    11      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FPPIkq%3A45%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PPIkq
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $value, !1 = $ok, !2 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      '1'
          2        BIND_STATIC                                              !2
   46     3        ECHO                                                     !1
   47     4        FETCH_DIM_R                                      ~3      !0, 'name'
          5        IS_EQUAL                                         ~4      !2, ~3
          6      > RETURN                                                   ~4
   48     7*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FPPIkq%3A45%240

Class ArrayFilters:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PPIkq
function name:  __construct
number of ops:  7
compiled vars:  !0 = $array, !1 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2        ASSIGN_OBJ                                               'array'
          3        OP_DATA                                                  !0
    8     4        ASSIGN_OBJ                                               'name'
          5        OP_DATA                                                  !1
    9     6      > RETURN                                                   null

End of function __construct

Function name_is:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PPIkq
function name:  name_is
number of ops:  6
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   13     1        FETCH_DIM_R                                      ~1      !0, 'name'
          2        FETCH_OBJ_R                                      ~2      'name'
          3        IS_EQUAL                                         ~3      ~1, ~2
          4      > RETURN                                                   ~3
   14     5*     > RETURN                                                   null

End of function name_is

End of class ArrayFilters.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.7 ms | 1400 KiB | 17 Q