3v4l.org

run code in 500+ PHP versions simultaneously
<?php $arr = array ( 0 => array ( 'id' => '1', 'p_pag' => '0', 'link' => 'Contact', 'children' => array ( 0 => array ( 'id' => '2', 'p_pag' => '1', 'link' => 'Contact-County', 'children' => array ( 0 => array ( 'id' => '3', 'p_pag' => '2', 'link' => 'Contact-Town-1', 'children' => array ( ), ), ), ), ), ), ); $searchId = 3; $link = null; $iterator = new \RecursiveIteratorIterator( new \RecursiveArrayIterator($arr),\RecursiveIteratorIterator::SELF_FIRST ); foreach($iterator as $subarr){ if(is_array($subarr) && array_key_exists('id',$subarr) && $subarr['id'] == $searchId){ $link = $subarr['link']; break; } } echo $link ? $link : 'not found';
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 26
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 26
Branch analysis from position: 13
2 jumps found. (Code = 46) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
2 jumps found. (Code = 46) Position 1 = 18, Position 2 = 21
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 25
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 30
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 21
Branch analysis from position: 17
Branch analysis from position: 26
Branch analysis from position: 26
filename:       /in/O0PAf
function name:  (null)
number of ops:  33
compiled vars:  !0 = $arr, !1 = $searchId, !2 = $link, !3 = $iterator, !4 = $subarr
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   33     1        ASSIGN                                                       !1, 3
   34     2        ASSIGN                                                       !2, null
   36     3        NEW                                                  $8      'RecursiveIteratorIterator'
   37     4        NEW                                                  $9      'RecursiveArrayIterator'
          5        SEND_VAR_EX                                                  !0
          6        DO_FCALL                                          0          
          7        SEND_VAR_NO_REF_EX                                           $9
          8        SEND_VAL_EX                                                  1
   36     9        DO_FCALL                                          0          
         10        ASSIGN                                                       !3, $8
   40    11      > FE_RESET_R                                           $13     !3, ->26
         12    > > FE_FETCH_R                                                   $13, !4, ->26
   41    13    >   TYPE_CHECK                                      128  ~14     !4
         14      > JMPZ_EX                                              ~14     ~14, ->17
         15    >   ARRAY_KEY_EXISTS                                     ~15     'id', !4
         16        BOOL                                                 ~14     ~15
         17    > > JMPZ_EX                                              ~14     ~14, ->21
         18    >   FETCH_DIM_R                                          ~16     !4, 'id'
         19        IS_EQUAL                                             ~17     !1, ~16
         20        BOOL                                                 ~14     ~17
         21    > > JMPZ                                                         ~14, ->25
   42    22    >   FETCH_DIM_R                                          ~18     !4, 'link'
         23        ASSIGN                                                       !2, ~18
   43    24      > JMP                                                          ->26
   40    25    > > JMP                                                          ->12
         26    >   FE_FREE                                                      $13
   47    27      > JMPZ                                                         !2, ->30
         28    >   QM_ASSIGN                                            ~20     !2
         29      > JMP                                                          ->31
         30    >   QM_ASSIGN                                            ~20     'not+found'
         31    >   ECHO                                                         ~20
         32      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
131.92 ms | 1881 KiB | 13 Q