3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array( array('id'=>1,'pid'=>'0','name'=>'11111'), array('id'=>2,'pid'=>'1','name'=>'22222'), array('id'=>3,'pid'=>'0','name'=>'33333'), array('id'=>4,'pid'=>'3','name'=>'44444'), array('id'=>5,'pid'=>'4','name'=>'55555'), array('id'=>6,'pid'=>'1','name'=>'66666')); function create_tree($arr,$pid=0) { $ret = array(); foreach($arr as $k => $v) { if($v['pid'] == $pid) { $tmp = $arr[$k];unset($arr[$k]); $tmp['children'] = create_tree($arr,$v['id']); $ret[] = $tmp; } } return $ret; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fsPCN
function name:  (null)
number of ops:  2
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    3     1      > RETURN                                                   1

Function create_tree:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 23
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 23
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 22
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 22
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/fsPCN
function name:  create_tree
number of ops:  26
compiled vars:  !0 = $arr, !1 = $pid, !2 = $ret, !3 = $v, !4 = $k, !5 = $tmp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
          0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
          2        ASSIGN                                                   !2, <array>
          3      > FE_RESET_R                                       $7      !0, ->23
          4    > > FE_FETCH_R                                       ~8      $7, !3, ->23
          5    >   ASSIGN                                                   !4, ~8
          6        FETCH_DIM_R                                      ~10     !3, 'pid'
          7        IS_EQUAL                                                 !1, ~10
          8      > JMPZ                                                     ~11, ->22
          9    >   FETCH_DIM_R                                      ~12     !0, !4
         10        ASSIGN                                                   !5, ~12
         11        UNSET_DIM                                                !0, !4
         12        INIT_FCALL_BY_NAME                                       'create_tree'
         13        SEND_VAR_EX                                              !0
         14        CHECK_FUNC_ARG                                           
         15        FETCH_DIM_FUNC_ARG                               $15     !3, 'id'
         16        SEND_FUNC_ARG                                            $15
         17        DO_FCALL                                      0  $16     
         18        ASSIGN_DIM                                               !5, 'children'
         19        OP_DATA                                                  $16
         20        ASSIGN_DIM                                               !2
         21        OP_DATA                                                  !5
         22    > > JMP                                                      ->4
         23    >   FE_FREE                                                  $7
         24      > RETURN                                                   !2
         25*     > RETURN                                                   null

End of function create_tree

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.64 ms | 1395 KiB | 13 Q