3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [ [ 'id' => 1, 'parent_id' => 0, 'access_type' => 'full-access', 'child' => [ [ 'id' => 4, 'parent_id' => 1, 'access_type' => '', ], [ 'id' => 5, 'parent_id' => 1, 'access_type' => '', ], ], ], [ 'id' => 2, 'parent_id' => 0, 'access_type' => 'read', 'child' => [ [ 'id' => 10, 'parent_id' => 2, 'access_type' => 'read-write', 'child' => [ [ 'id' => 11, 'parent_id' => 10, 'access_type' => '', ], [ 'id' => 12, 'parent_id' => 10, 'access_type' => 'read', ], ], ], [ 'id' => 7, 'parent_id' => 3, 'access_type' => 'read-write', ], ], ], [ 'id' => 3, 'parent_id' => 0, 'access_type' => 'full-access', 'child' => [ [ 'id' => 6, 'parent_id' => 3, 'access_type' => '', 'child' => [ [ 'id' => 8, 'parent_id' => 6, 'access_type' => '', ], [ 'id' => 9, 'parent_id' => 6, 'access_type' => '', ], ], ], [ 'id' => 18, 'parent_id' => 3, 'access_type' => '', ], ], ], [ 'id' => 13, 'parent_id' => 0, 'access_type' => '', 'child' => [ [ 'id' => 14, 'parent_id' => 13, 'access_type' => 'full-access', 'child' => [ [ 'id' => 15, 'parent_id' => 14, 'access_type' => '', ], [ 'id' => 16, 'parent_id' => 14, 'access_type' => '', ], ], ], [ 'id' => 17, 'parent_id' => 13, 'access_type' => '', ], ], ], ]; func_x($arr); function func_x($arr, $level = 0, $parent = '') { foreach($arr as $x) { if( empty ( $x['access_type'] ) && $parent == 'full-access' ) { $x['access_type'] = $parent; } echo str_repeat("---", $level) . " [" . $x['id'] . "] -> " . $x['access_type'] . "\n"; if(!empty($x['child'])) { func_x($x['child'], $level+1, $x['access_type']); } } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Vk5ZQ
function name:  (null)
number of ops:  5
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
  111     1        INIT_FCALL_BY_NAME                                       'func_x'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
  127     4      > RETURN                                                   1

Function func_x:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 38
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 38
Branch analysis from position: 5
2 jumps found. (Code = 46) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 37
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 37
Branch analysis from position: 12
Branch analysis from position: 9
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
filename:       /in/Vk5ZQ
function name:  func_x
number of ops:  40
compiled vars:  !0 = $arr, !1 = $level, !2 = $parent, !3 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  113     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
          2        RECV_INIT                                        !2      ''
  115     3      > FE_RESET_R                                       $4      !0, ->38
          4    > > FE_FETCH_R                                               $4, !3, ->38
  117     5    >   ISSET_ISEMPTY_DIM_OBJ                         1  ~5      !3, 'access_type'
          6      > JMPZ_EX                                          ~5      ~5, ->9
          7    >   IS_EQUAL                                         ~6      !2, 'full-access'
          8        BOOL                                             ~5      ~6
          9    > > JMPZ                                                     ~5, ->12
  118    10    >   ASSIGN_DIM                                               !3, 'access_type'
         11        OP_DATA                                                  !2
  120    12    >   INIT_FCALL                                               'str_repeat'
         13        SEND_VAL                                                 '---'
         14        SEND_VAR                                                 !1
         15        DO_ICALL                                         $8      
         16        CONCAT                                           ~9      $8, '+%5B'
         17        FETCH_DIM_R                                      ~10     !3, 'id'
         18        CONCAT                                           ~11     ~9, ~10
         19        CONCAT                                           ~12     ~11, '%5D+-%3E+'
         20        FETCH_DIM_R                                      ~13     !3, 'access_type'
         21        CONCAT                                           ~14     ~12, ~13
         22        CONCAT                                           ~15     ~14, '%0A'
         23        ECHO                                                     ~15
  122    24        ISSET_ISEMPTY_DIM_OBJ                         1  ~16     !3, 'child'
         25        BOOL_NOT                                         ~17     ~16
         26      > JMPZ                                                     ~17, ->37
  124    27    >   INIT_FCALL_BY_NAME                                       'func_x'
         28        CHECK_FUNC_ARG                                           
         29        FETCH_DIM_FUNC_ARG                               $18     !3, 'child'
         30        SEND_FUNC_ARG                                            $18
         31        ADD                                              ~19     !1, 1
         32        SEND_VAL_EX                                              ~19
         33        CHECK_FUNC_ARG                                           
         34        FETCH_DIM_FUNC_ARG                               $20     !3, 'access_type'
         35        SEND_FUNC_ARG                                            $20
         36        DO_FCALL                                      0          
  115    37    > > JMP                                                      ->4
         38    >   FE_FREE                                                  $4
  127    39      > RETURN                                                   null

End of function func_x

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.2 ms | 1015 KiB | 14 Q