3v4l.org

run code in 300+ PHP versions simultaneously
<?php $list = [ [ 'name' => 'this is items name', 'number' => 1, 'description' => 'this is description', 'id' => 'just some id' ], [ 'name' => 'this is items name2', 'number' => 1, 'description' => 'this is description2', 'id' => 'just some id' ], 'test' => [ 'name' => 'this is items name3', 'number' => 1, 'description' => 'do not find this one', 'id' => 'just some id' ], 'preserve_this_key_please' => [ 'name' => 'this is items name4', 'number' => 1, 'description' => 'this is something, key preserved', 'id' => 'just some id' ], ]; function getKeysBy($array, $key, $value){ return array_keys(array_filter($array,function($val) use ($key,$value) { //return $val[$key] === $value;//exact match return strpos($val[$key], $value) === 0; } )); } var_dump(getKeysBy($list, 'description', 'this is'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Gs3He
function name:  (null)
number of ops:  10
compiled vars:  !0 = $list
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   39     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'getkeysby'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 'description'
          5        SEND_VAL                                                 'this+is'
          6        DO_FCALL                                      0  $2      
          7        SEND_VAR                                                 $2
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Function getkeysby:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Gs3He
function name:  getKeysBy
number of ops:  15
compiled vars:  !0 = $array, !1 = $key, !2 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   34     3        INIT_FCALL                                               'array_keys'
          4        INIT_FCALL                                               'array_filter'
          5        SEND_VAR                                                 !0
          6        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FGs3He%3A34%240'
          7        BIND_LEXICAL                                             ~3, !1
          8        BIND_LEXICAL                                             ~3, !2
   37     9        SEND_VAL                                                 ~3
         10        DO_ICALL                                         $4      
         11        SEND_VAR                                                 $4
         12        DO_ICALL                                         $5      
         13      > RETURN                                                   $5
   38    14*     > RETURN                                                   null

End of function getkeysby

Function %00%7Bclosure%7D%2Fin%2FGs3He%3A34%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Gs3He
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $val, !1 = $key, !2 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
   36     3        INIT_FCALL                                               'strpos'
          4        FETCH_DIM_R                                      ~3      !0, !1
          5        SEND_VAL                                                 ~3
          6        SEND_VAR                                                 !2
          7        DO_ICALL                                         $4      
          8        IS_IDENTICAL                                     ~5      $4, 0
          9      > RETURN                                                   ~5
   37    10*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FGs3He%3A34%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.01 ms | 1403 KiB | 22 Q