3v4l.org

run code in 300+ PHP versions simultaneously
<?php function create_tree($arr,$pid=0) {$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'));echo "<pre>";print_r(create_tree($arr)); $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/JjSom
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E > > RETURN                                                   1

Function create_tree:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 31
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 31
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 30
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
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/JjSom
function name:  create_tree
number of ops:  34
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                                                   !0, <array>
          3        ECHO                                                     '%3Cpre%3E'
          4        INIT_FCALL                                               'print_r'
          5        INIT_FCALL_BY_NAME                                       'create_tree'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0  $7      
          8        SEND_VAR                                                 $7
          9        DO_ICALL                                                 
         10        ASSIGN                                                   !2, <array>
         11      > FE_RESET_R                                       $10     !0, ->31
         12    > > FE_FETCH_R                                       ~11     $10, !3, ->31
         13    >   ASSIGN                                                   !4, ~11
         14        FETCH_DIM_R                                      ~13     !3, 'pid'
         15        IS_EQUAL                                                 !1, ~13
         16      > JMPZ                                                     ~14, ->30
         17    >   FETCH_DIM_R                                      ~15     !0, !4
         18        ASSIGN                                                   !5, ~15
         19        UNSET_DIM                                                !0, !4
         20        INIT_FCALL_BY_NAME                                       'create_tree'
         21        SEND_VAR_EX                                              !0
         22        CHECK_FUNC_ARG                                           
         23        FETCH_DIM_FUNC_ARG                               $18     !3, 'id'
         24        SEND_FUNC_ARG                                            $18
         25        DO_FCALL                                      0  $19     
         26        ASSIGN_DIM                                               !5, 'children'
         27        OP_DATA                                                  $19
         28        ASSIGN_DIM                                               !2
         29        OP_DATA                                                  !5
         30    > > JMP                                                      ->12
         31    >   FE_FREE                                                  $10
         32      > RETURN                                                   !2
         33*     > RETURN                                                   null

End of function create_tree

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
205.05 ms | 1400 KiB | 15 Q