3v4l.org

run code in 300+ PHP versions simultaneously
<?php function findElementR(&$array, $id) { foreach($array AS &$v){ if($v['id'] == $id){ $v['children'] = []; 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/umaG2
function name:  (null)
number of ops:  15
compiled vars:  !0 = $ar, !1 = $n
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   ASSIGN                                                   !0, <array>
   16     1        INIT_FCALL                                               'findelementr'
          2        SEND_REF                                                 !0
          3        SEND_VAL                                                 1
          4        DO_FCALL                                      0  $3      
          5        ASSIGN                                                   !1, $3
   17     6        INIT_FCALL                                               'print_r'
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                                 
   18     9        ASSIGN_DIM                                               !1, 'children'
         10        OP_DATA                                                  <array>
   19    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 = 27
Branch analysis from position: 3
2 jumps found. (Code = 126) Position 1 = 4, Position 2 = 27
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 26
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 26
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 26
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/umaG2
function name:  findElementR
number of ops:  29
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, ->27
          3    > > FE_FETCH_RW                                              $4, !2, ->27
    5     4    >   FETCH_DIM_R                                      ~5      !2, 'id'
          5        IS_EQUAL                                                 !1, ~5
          6      > JMPZ                                                     ~6, ->11
    6     7    >   ASSIGN_DIM                                               !2, 'children'
          8        OP_DATA                                                  <array>
    7     9        FE_FREE                                                  $4
         10      > RETURN                                                   !2
    9    11    >   ISSET_ISEMPTY_DIM_OBJ                         1  ~8      !2, 'children'
         12        BOOL_NOT                                         ~9      ~8
         13      > JMPZ                                                     ~9, ->26
   10    14    >   INIT_FCALL_BY_NAME                                       'findElementR'
         15        CHECK_FUNC_ARG                                           
         16        FETCH_DIM_FUNC_ARG                               $10     !3, 'children'
         17        SEND_FUNC_ARG                                            $10
         18        SEND_VAR_EX                                              !1
         19        DO_FCALL                                      0  $11     
         20        ASSIGN                                                   !3, $11
   11    21        ISSET_ISEMPTY_CV                                 ~13     !3
         22        BOOL_NOT                                         ~14     ~13
         23      > JMPZ                                                     ~14, ->26
         24    >   FE_FREE                                                  $4
         25      > RETURN                                                   !3
    4    26    > > JMP                                                      ->3
         27    >   FE_FREE                                                  $4
   14    28      > RETURN                                                   null

End of function findelementr

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.47 ms | 1403 KiB | 16 Q