3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 0 => [ "id" => 1, "name" => "Sammy", "phone" => "2348055643322", "email" => "sammy@abc.com" ], 1 => [ "id" => 2, "name" => "Saheed", "phone" => "", "email" => "saay@aol.com" ], 2 => [ "id" => 3, "name" => "Edwin", "phone" => "2348099993322", "email" => "eddy@gmail.com" ], 3 => [ "id" => 3, "name" => "Jonadab", "phone" => "2348066773322", "email" => "jonadab@gmail.com" ], 4 => [ "id" => 3, "name" => "Mercy", "phone" => "", "email" => "mercy@sysnet.com" ] ]; $start = microtime(true); $phone = array_filter(array_column($array, "phone")); $filtered = array_intersect_key($array, $phone); Echo "array_intersect_key: " . (microtime(true)-$start)*1000; $start = microtime(true); $column = 'phone'; //column to filter $result = array_filter($array, function($o) use($column) { return trim( $o[$column] ) !== '' && $o[$column] !== null; }); Echo "\n\narray_filter: " . (microtime(true)-$start)*1000; $start = microtime(true); foreach ($array as $index => $row) { if (strlen($row['phone'])) { // keep the original index $response [$index]= $row; } } Echo "\n\nforeach: " . (microtime(true)-$start)*1000; $start = microtime(true); $reulting_array = array_filter($array, function ($entry) { return !empty($entry['phone']); }); Echo "\n\narray_filter by SaAy: " . (microtime(true)-$start)*1000;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 49, Position 2 = 57
Branch analysis from position: 49
2 jumps found. (Code = 78) Position 1 = 50, Position 2 = 57
Branch analysis from position: 50
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 56
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
Branch analysis from position: 56
Branch analysis from position: 57
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 57
filename:       /in/nafbq
function name:  (null)
number of ops:  83
compiled vars:  !0 = $array, !1 = $start, !2 = $phone, !3 = $filtered, !4 = $column, !5 = $result, !6 = $row, !7 = $index, !8 = $response, !9 = $reulting_array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   39     1        INIT_FCALL                                               'microtime'
          2        SEND_VAL                                                 <true>
          3        DO_ICALL                                         $11     
          4        ASSIGN                                                   !1, $11
   40     5        INIT_FCALL                                               'array_filter'
          6        INIT_FCALL                                               'array_column'
          7        SEND_VAR                                                 !0
          8        SEND_VAL                                                 'phone'
          9        DO_ICALL                                         $13     
         10        SEND_VAR                                                 $13
         11        DO_ICALL                                         $14     
         12        ASSIGN                                                   !2, $14
   42    13        INIT_FCALL                                               'array_intersect_key'
         14        SEND_VAR                                                 !0
         15        SEND_VAR                                                 !2
         16        DO_ICALL                                         $16     
         17        ASSIGN                                                   !3, $16
   43    18        INIT_FCALL                                               'microtime'
         19        SEND_VAL                                                 <true>
         20        DO_ICALL                                         $18     
         21        SUB                                              ~19     $18, !1
         22        MUL                                              ~20     ~19, 1000
         23        CONCAT                                           ~21     'array_intersect_key%3A+', ~20
         24        ECHO                                                     ~21
   47    25        INIT_FCALL                                               'microtime'
         26        SEND_VAL                                                 <true>
         27        DO_ICALL                                         $22     
         28        ASSIGN                                                   !1, $22
   48    29        ASSIGN                                                   !4, 'phone'
   50    30        INIT_FCALL                                               'array_filter'
         31        SEND_VAR                                                 !0
         32        DECLARE_LAMBDA_FUNCTION                          ~25     [0]
         33        BIND_LEXICAL                                             ~25, !4
   52    34        SEND_VAL                                                 ~25
   50    35        DO_ICALL                                         $26     
         36        ASSIGN                                                   !5, $26
   53    37        INIT_FCALL                                               'microtime'
         38        SEND_VAL                                                 <true>
         39        DO_ICALL                                         $28     
         40        SUB                                              ~29     $28, !1
         41        MUL                                              ~30     ~29, 1000
         42        CONCAT                                           ~31     '%0A%0Aarray_filter%3A+', ~30
         43        ECHO                                                     ~31
   58    44        INIT_FCALL                                               'microtime'
         45        SEND_VAL                                                 <true>
         46        DO_ICALL                                         $32     
         47        ASSIGN                                                   !1, $32
   59    48      > FE_RESET_R                                       $34     !0, ->57
         49    > > FE_FETCH_R                                       ~35     $34, !6, ->57
         50    >   ASSIGN                                                   !7, ~35
   61    51        FETCH_DIM_R                                      ~37     !6, 'phone'
         52        STRLEN                                           ~38     ~37
         53      > JMPZ                                                     ~38, ->56
   63    54    >   ASSIGN_DIM                                               !8, !7
         55        OP_DATA                                                  !6
   59    56    > > JMP                                                      ->49
         57    >   FE_FREE                                                  $34
   66    58        INIT_FCALL                                               'microtime'
         59        SEND_VAL                                                 <true>
         60        DO_ICALL                                         $40     
         61        SUB                                              ~41     $40, !1
         62        MUL                                              ~42     ~41, 1000
         63        CONCAT                                           ~43     '%0A%0Aforeach%3A+', ~42
         64        ECHO                                                     ~43
   70    65        INIT_FCALL                                               'microtime'
         66        SEND_VAL                                                 <true>
         67        DO_ICALL                                         $44     
         68        ASSIGN                                                   !1, $44
   71    69        INIT_FCALL                                               'array_filter'
         70        SEND_VAR                                                 !0
         71        DECLARE_LAMBDA_FUNCTION                          ~46     [1]
   73    72        SEND_VAL                                                 ~46
   71    73        DO_ICALL                                         $47     
         74        ASSIGN                                                   !9, $47
   74    75        INIT_FCALL                                               'microtime'
         76        SEND_VAL                                                 <true>
         77        DO_ICALL                                         $49     
         78        SUB                                              ~50     $49, !1
         79        MUL                                              ~51     ~50, 1000
         80        CONCAT                                           ~52     '%0A%0Aarray_filter+by+SaAy%3A+', ~51
         81        ECHO                                                     ~52
   75    82      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 8, Position 2 = 11
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/nafbq
function name:  {closure}
number of ops:  13
compiled vars:  !0 = $o, !1 = $column
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   51     2        INIT_FCALL                                               'trim'
          3        FETCH_DIM_R                                      ~2      !0, !1
          4        SEND_VAL                                                 ~2
          5        DO_ICALL                                         $3      
          6        IS_NOT_IDENTICAL                                 ~4      $3, ''
          7      > JMPZ_EX                                          ~4      ~4, ->11
          8    >   FETCH_DIM_R                                      ~5      !0, !1
          9        TYPE_CHECK                                  1020  ~6      ~5
         10        BOOL                                             ~4      ~6
         11    > > RETURN                                                   ~4
   52    12*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nafbq
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $entry
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   71     0  E >   RECV                                             !0      
   72     1        ISSET_ISEMPTY_DIM_OBJ                         1  ~1      !0, 'phone'
          2        BOOL_NOT                                         ~2      ~1
          3      > RETURN                                                   ~2
   73     4*     > RETURN                                                   null

End of Dynamic Function 1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.81 ms | 1011 KiB | 18 Q