3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ [ 'id' => 1, 'some_key' => 'some_value', 'attribute' => [ 'id' => 45, 'cat_id' => 1 ], 'sub' => [ 'id' => 17, 'some_key' => 'some_value', 'attribute' => [ 'id' => 47, 'cat_id' => 17 ], ], ], [ 'id' => 2, 'some_key' => 'some_value', 'sub' => [ 'id' => 19, 'some_key' => 'some_value', ], ] ]; $childArray = []; function collectIDs($arr,&$childArray){ foreach($arr as $key => $value){ if($key === 'attribute') continue; if(is_array($value)) collectIDs($value,$childArray); else if($key == 'id') $childArray[] = $value; } } collectIDs($array,$childArray); print_r($childArray);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/V6uFf
function name:  (null)
number of ops:  10
compiled vars:  !0 = $array, !1 = $childArray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   30     1        ASSIGN                                                   !1, <array>
   40     2        INIT_FCALL                                               'collectids'
          3        SEND_VAR                                                 !0
          4        SEND_REF                                                 !1
          5        DO_FCALL                                      0          
   41     6        INIT_FCALL                                               'print_r'
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Function collectids:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 20
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 20
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 15
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 19
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/V6uFf
function name:  collectIDs
number of ops:  22
compiled vars:  !0 = $arr, !1 = $childArray, !2 = $value, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   33     2      > FE_RESET_R                                       $4      !0, ->20
          3    > > FE_FETCH_R                                       ~5      $4, !2, ->20
          4    >   ASSIGN                                                   !3, ~5
   34     5        IS_IDENTICAL                                             !3, 'attribute'
          6      > JMPZ                                                     ~7, ->8
          7    > > JMP                                                      ->3
   35     8    >   TYPE_CHECK                                  128          !2
          9      > JMPZ                                                     ~8, ->15
         10    >   INIT_FCALL_BY_NAME                                       'collectIDs'
         11        SEND_VAR_EX                                              !2
         12        SEND_VAR_EX                                              !1
         13        DO_FCALL                                      0          
         14      > JMP                                                      ->19
   36    15    >   IS_EQUAL                                                 !3, 'id'
         16      > JMPZ                                                     ~10, ->19
         17    >   ASSIGN_DIM                                               !1
         18        OP_DATA                                                  !2
   33    19    > > JMP                                                      ->3
         20    >   FE_FREE                                                  $4
   38    21      > RETURN                                                   null

End of function collectids

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.03 ms | 1005 KiB | 15 Q