3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getLibItemByName($array,$name){ // avoid global, assign as parameter foreach($array['library'] as $key => $row){ if($name === $row['name']){ return $row; // return the whole subarray } } return false; } // logically rename json to array $array=[ 'library'=> [ ['name'=>'Alan','age'=>5], ['name'=>'Bert','age'=>6], ['name'=>'Chad','age'=>7], ['name'=>'Doug','age'=>8], ['name'=>'Eddy','age'=>9], ['name'=>'Fred','age'=>10] ] ]; var_export(getLibItemByName($array,'Chad')); echo "\n---\n"; var_export(getLibItemByName($array,'Greg')); echo "\n---\n"; if(($index=array_search('Eddy',array_column($array['library'],'name')))!==false){ var_export($array['library'][$index]); }else{ echo 'No match'; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 35
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7MZDa
function name:  (null)
number of ops:  37
compiled vars:  !0 = $array, !1 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   ASSIGN                                                   !0, <array>
   24     1        INIT_FCALL                                               'var_export'
          2        INIT_FCALL                                               'getlibitembyname'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 'Chad'
          5        DO_FCALL                                      0  $3      
          6        SEND_VAR                                                 $3
          7        DO_ICALL                                                 
   25     8        ECHO                                                     '%0A---%0A'
   26     9        INIT_FCALL                                               'var_export'
         10        INIT_FCALL                                               'getlibitembyname'
         11        SEND_VAR                                                 !0
         12        SEND_VAL                                                 'Greg'
         13        DO_FCALL                                      0  $5      
         14        SEND_VAR                                                 $5
         15        DO_ICALL                                                 
   28    16        ECHO                                                     '%0A---%0A'
   30    17        INIT_FCALL                                               'array_search'
         18        SEND_VAL                                                 'Eddy'
         19        INIT_FCALL                                               'array_column'
         20        FETCH_DIM_R                                      ~7      !0, 'library'
         21        SEND_VAL                                                 ~7
         22        SEND_VAL                                                 'name'
         23        DO_ICALL                                         $8      
         24        SEND_VAR                                                 $8
         25        DO_ICALL                                         $9      
         26        ASSIGN                                           ~10     !1, $9
         27        TYPE_CHECK                                  1018          ~10
         28      > JMPZ                                                     ~11, ->35
   31    29    >   INIT_FCALL                                               'var_export'
         30        FETCH_DIM_R                                      ~12     !0, 'library'
         31        FETCH_DIM_R                                      ~13     ~12, !1
         32        SEND_VAL                                                 ~13
         33        DO_ICALL                                                 
   30    34      > JMP                                                      ->36
   33    35    >   ECHO                                                     'No+match'
   34    36    > > RETURN                                                   1

Function getlibitembyname:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 12
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/7MZDa
function name:  getLibItemByName
number of ops:  15
compiled vars:  !0 = $array, !1 = $name, !2 = $row, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    3     2        FETCH_DIM_R                                      ~4      !0, 'library'
          3      > FE_RESET_R                                       $5      ~4, ->12
          4    > > FE_FETCH_R                                       ~6      $5, !2, ->12
          5    >   ASSIGN                                                   !3, ~6
    4     6        FETCH_DIM_R                                      ~8      !2, 'name'
          7        IS_IDENTICAL                                             !1, ~8
          8      > JMPZ                                                     ~9, ->11
    5     9    >   FE_FREE                                                  $5
         10      > RETURN                                                   !2
    3    11    > > JMP                                                      ->4
         12    >   FE_FREE                                                  $5
    8    13      > RETURN                                                   <false>
    9    14*     > RETURN                                                   null

End of function getlibitembyname

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.34 ms | 1009 KiB | 18 Q