3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array( array("title" => 1, "children" => array( array( "selected" => true, "key" => 100, "children" => array() ) ), array( "selected" => true, "key" => 200, "children" => array( array( "selected" => true, "key" => 300, "children" => array( array( "selected" => true, "key" => 400, "children" => array() ) ) ) ) ) ) ); $selectedValues = array(); $iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($array)); foreach ($iterator as $key => $value) { if ($key == "selected") { $depth = $iterator->getDepth(); $subIterator = $iterator->getSubIterator($depth); foreach ($subIterator as $key2 => $value2) { if ($key2 == "key") { echo $value2 . PHP_EOL; } } } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 31
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 31
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 30
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 22, Position 2 = 29
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 29
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 28
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 28
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 29
Branch analysis from position: 30
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/0Aasc
function name:  (null)
number of ops:  33
compiled vars:  !0 = $array, !1 = $selectedValues, !2 = $iterator, !3 = $value, !4 = $key, !5 = $depth, !6 = $subIterator, !7 = $value2, !8 = $key2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   29     1        ASSIGN                                                   !1, <array>
   30     2        NEW                                              $11     'RecursiveIteratorIterator'
          3        NEW                                              $12     'RecursiveArrayIterator'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0          
          6        SEND_VAR_NO_REF_EX                                       $12
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !2, $11
   31     9      > FE_RESET_R                                       $16     !2, ->31
         10    > > FE_FETCH_R                                       ~17     $16, !3, ->31
         11    >   ASSIGN                                                   !4, ~17
   32    12        IS_EQUAL                                                 !4, 'selected'
         13      > JMPZ                                                     ~19, ->30
   33    14    >   INIT_METHOD_CALL                                         !2, 'getDepth'
         15        DO_FCALL                                      0  $20     
         16        ASSIGN                                                   !5, $20
   34    17        INIT_METHOD_CALL                                         !2, 'getSubIterator'
         18        SEND_VAR_EX                                              !5
         19        DO_FCALL                                      0  $22     
         20        ASSIGN                                                   !6, $22
   35    21      > FE_RESET_R                                       $24     !6, ->29
         22    > > FE_FETCH_R                                       ~25     $24, !7, ->29
         23    >   ASSIGN                                                   !8, ~25
   36    24        IS_EQUAL                                                 !8, 'key'
         25      > JMPZ                                                     ~27, ->28
   37    26    >   CONCAT                                           ~28     !7, '%0A'
         27        ECHO                                                     ~28
   35    28    > > JMP                                                      ->22
         29    >   FE_FREE                                                  $24
   31    30    > > JMP                                                      ->10
         31    >   FE_FREE                                                  $16
   41    32      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.68 ms | 1399 KiB | 13 Q