3v4l.org

run code in 300+ PHP versions simultaneously
<?php function findElementR(&$array, $id) { foreach($array AS &$v){ if($v['id'] == $id) return $v; if(!empty($v['children'])){ $_n = findElementR($_n['children'], $id); if(!empty($_n)) return $_n; } } } $ar = [['parentId'=>3,'id'=>1],['parentId'=>3,'id'=>2]]; $n= findElementR($ar,1); print_r($n); $n['children'] = []; print_r($ar);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fqWJp
function name:  (null)
number of ops:  15
compiled vars:  !0 = $ar, !1 = $n
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   ASSIGN                                                   !0, <array>
   13     1        INIT_FCALL                                               'findelementr'
          2        SEND_REF                                                 !0
          3        SEND_VAL                                                 1
          4        DO_FCALL                                      0  $3      
          5        ASSIGN                                                   !1, $3
   14     6        INIT_FCALL                                               'print_r'
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                                 
   15     9        ASSIGN_DIM                                               !1, 'children'
         10        OP_DATA                                                  <array>
   16    11        INIT_FCALL                                               'print_r'
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                                 
         14      > RETURN                                                   1

Function findelementr:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 3, Position 2 = 25
Branch analysis from position: 3
2 jumps found. (Code = 126) Position 1 = 4, Position 2 = 25
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 24
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 24
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 24
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/fqWJp
function name:  findElementR
number of ops:  27
compiled vars:  !0 = $array, !1 = $id, !2 = $v, !3 = $_n
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2      > FE_RESET_RW                                      $4      !0, ->25
          3    > > FE_FETCH_RW                                              $4, !2, ->25
    5     4    >   FETCH_DIM_R                                      ~5      !2, 'id'
          5        IS_EQUAL                                                 !1, ~5
          6      > JMPZ                                                     ~6, ->9
          7    >   FE_FREE                                                  $4
          8      > RETURN                                                   !2
    6     9    >   ISSET_ISEMPTY_DIM_OBJ                         1  ~7      !2, 'children'
         10        BOOL_NOT                                         ~8      ~7
         11      > JMPZ                                                     ~8, ->24
    7    12    >   INIT_FCALL_BY_NAME                                       'findElementR'
         13        CHECK_FUNC_ARG                                           
         14        FETCH_DIM_FUNC_ARG                               $9      !3, 'children'
         15        SEND_FUNC_ARG                                            $9
         16        SEND_VAR_EX                                              !1
         17        DO_FCALL                                      0  $10     
         18        ASSIGN                                                   !3, $10
    8    19        ISSET_ISEMPTY_CV                                 ~12     !3
         20        BOOL_NOT                                         ~13     ~12
         21      > JMPZ                                                     ~13, ->24
         22    >   FE_FREE                                                  $4
         23      > RETURN                                                   !3
    4    24    > > JMP                                                      ->3
         25    >   FE_FREE                                                  $4
   11    26      > RETURN                                                   null

End of function findelementr

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.19 ms | 1403 KiB | 16 Q