3v4l.org

run code in 300+ PHP versions simultaneously
<?php $category = '{"9":{"id":"9","btc_mlm_user_id":"0","lft":"1","rht":"16","lvl":"0","name":"Root","created":"2017-06-27 05:56:11","modified":"2017-06-27 05:56:11","first_name":"","last_name":"","username":""},"42":{"id":"42","btc_mlm_user_id":"25","lft":"2","rht":"13","lvl":"1","name":"naresh","created":"2017-11-02 10:22:24","modified":"2017-11-02 10:22:24","first_name":"","last_name":"","username":"naresh"},"44":{"id":"44","btc_mlm_user_id":"27","lft":"3","rht":"4","lvl":"2","name":"rahul1","created":"2017-11-02 10:25:53","modified":"2017-11-02 10:25:53","first_name":"","last_name":"","username":"rahul1"},"45":{"id":"45","btc_mlm_user_id":"28","lft":"5","rht":"6","lvl":"2","name":"rahul123","created":"2017-11-02 10:27:19","modified":"2017-11-02 10:27:19","first_name":"","last_name":"","username":"rahul123"},"46":{"id":"46","btc_mlm_user_id":"29","lft":"7","rht":"12","lvl":"2","name":"kapil1","created":"2017-11-02 10:28:20","modified":"2017-11-02 10:28:20","first_name":"","last_name":"","username":"kapil1"},"47":{"id":"47","btc_mlm_user_id":"30","lft":"8","rht":"11","lvl":"3","name":"priya12","created":"2017-11-02 10:30:30","modified":"2017-11-02 10:30:30","first_name":"","last_name":"","username":"priya12"},"48":{"id":"48","btc_mlm_user_id":"31","lft":"9","rht":"10","lvl":"4","name":"amit12","created":"2017-11-02 10:32:00","modified":"2017-11-02 10:32:00","first_name":"","last_name":"","username":"amit12"},"43":{"id":"43","btc_mlm_user_id":"26","lft":"14","rht":"15","lvl":"1","name":"roshan","created":"2017-11-02 10:24:27","modified":"2017-11-02 10:24:27","first_name":"","last_name":"","username":"roshan"}}'; $t = []; function tree($data, $left = 0, $right = null) { $tree = array(); foreach ($data as $key => $value) { if ($value['lft'] == $left + 1 && (is_null($right) || $value['rht'] < $right)) { $tree[$key]['text'] = ['name' => $value['name']]; $tree[$key]['children'] = tree($data, $value['lft'], $value['rht']); $left = $value['rht']; } } return $tree; } $tree = tree(json_decode($category, true)); print_r($tree); echo json_encode($tree);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UsXPv
function name:  (null)
number of ops:  18
compiled vars:  !0 = $category, !1 = $t, !2 = $tree
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%7B%229%22%3A%7B%22id%22%3A%229%22%2C%22btc_mlm_user_id%22%3A%220%22%2C%22lft%22%3A%221%22%2C%22rht%22%3A%2216%22%2C%22lvl%22%3A%220%22%2C%22name%22%3A%22Root%22%2C%22created%22%3A%222017-06-27+05%3A56%3A11%22%2C%22modified%22%3A%222017-06-27+05%3A56%3A11%22%2C%22first_name%22%3A%22%22%2C%22last_name%22%3A%22%22%2C%22username%22%3A%22%22%7D%2C%2242%22%3A%7B%22id%22%3A%2242%22%2C%22btc_mlm_user_id%22%3A%2225%22%2C%22lft%22%3A%222%22%2C%22rht%22%3A%2213%22%2C%22lvl%22%3A%221%22%2C%22name%22%3A%22naresh%22%2C%22created%22%3A%222017-11-02+10%3A22%3A24%22%2C%22modified%22%3A%222017-11-02+10%3A22%3A24%22%2C%22first_name%22%3A%22%22%2C%22last_name%22%3A%22%22%2C%22username%22%3A%22naresh%22%7D%2C%2244%22%3A%7B%22id%22%3A%2244%22%2C%22btc_mlm_user_id%22%3A%2227%22%2C%22lft%22%3A%223%22%2C%22rht%22%3A%224%22%2C%22lvl%22%3A%222%22%2C%22name%22%3A%22rahul1%22%2C%22created%22%3A%222017-11-02+10%3A25%3A53%22%2C%22modified%22%3A%222017-11-02+10%3A25%3A53%22%2C%22first_name%22%3A%22%22%2C%22last_name%22%3A%22%22%2C%22username%22%3A%22rahul1%22%7D%2C%2245%22%3A%7B%22id%22%3A%2245%22%2C%22btc_mlm_user_id%22%3A%2228%22%2C%22lft%22%3A%225%22%2C%22rht%22%3A%226%22%2C%22lvl%22%3A%222%22%2C%22name%22%3A%22rahul123%22%2C%22created%22%3A%222017-11-02+10%3A27%3A19%22%2C%22modified%22%3A%222017-11-02+10%3A27%3A19%22%2C%22first_name%22%3A%22%22%2C%22last_name%22%3A%22%22%2C%22username%22%3A%22rahul123%22%7D%2C%2246%22%3A%7B%22id%22%3A%2246%22%2C%22btc_mlm_user_id%22%3A%2229%22%2C%22lft%22%3A%227%22%2C%22rht%22%3A%2212%22%2C%22lvl%22%3A%222%22%2C%22name%22%3A%22kapil1%22%2C%22created%22%3A%222017-11-02+10%3A28%3A20%22%2C%22modified%22%3A%222017-11-02+10%3A28%3A20%22%2C%22first_name%22%3A%22%22%2C%22last_name%22%3A%22%22%2C%22username%22%3A%22kapil1%22%7D%2C%2247%22%3A%7B%22id%22%3A%2247%22%2C%22btc_mlm_user_id%22%3A%2230%22%2C%22lft%22%3A%228%22%2C%22rht%22%3A%2211%22%2C%22lvl%22%3A%223%22%2C%22name%22%3A%22priya12%22%2C%22created%22%3A%222017-11-02+10%3A30%3A30%22%2C%22modified%22%3A%222017-11-02+10%3A30%3A30%22%2C%22first_name%22%3A%22%22%2C%22last_name%22%3A%22%22%2C%22username%22%3A%22priya12%22%7D%2C%2248%22%3A%7B%22id%22%3A%2248%22%2C%22btc_mlm_user_id%22%3A%2231%22%2C%22lft%22%3A%229%22%2C%22rht%22%3A%2210%22%2C%22lvl%22%3A%224%22%2C%22name%22%3A%22amit12%22%2C%22created%22%3A%222017-11-02+10%3A32%3A00%22%2C%22modified%22%3A%222017-11-02+10%3A32%3A00%22%2C%22first_name%22%3A%22%22%2C%22last_name%22%3A%22%22%2C%22username%22%3A%22amit12%22%7D%2C%2243%22%3A%7B%22id%22%3A%2243%22%2C%22btc_mlm_user_id%22%3A%2226%22%2C%22lft%22%3A%2214%22%2C%22rht%22%3A%2215%22%2C%22lvl%22%3A%221%22%2C%22name%22%3A%22roshan%22%2C%22created%22%3A%222017-11-02+10%3A24%3A27%22%2C%22modified%22%3A%222017-11-02+10%3A24%3A27%22%2C%22first_name%22%3A%22%22%2C%22last_name%22%3A%22%22%2C%22username%22%3A%22roshan%22%7D%7D'
    5     1        ASSIGN                                                   !1, <array>
   18     2        INIT_FCALL                                               'tree'
          3        INIT_FCALL                                               'json_decode'
          4        SEND_VAR                                                 !0
          5        SEND_VAL                                                 <true>
          6        DO_ICALL                                         $5      
          7        SEND_VAR                                                 $5
          8        DO_FCALL                                      0  $6      
          9        ASSIGN                                                   !2, $6
   20    10        INIT_FCALL                                               'print_r'
         11        SEND_VAR                                                 !2
         12        DO_ICALL                                                 
   22    13        INIT_FCALL                                               'json_encode'
         14        SEND_VAR                                                 !2
         15        DO_ICALL                                         $9      
         16        ECHO                                                     $9
         17      > RETURN                                                   1

Function tree:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 38
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 38
Branch analysis from position: 6
2 jumps found. (Code = 46) Position 1 = 11, Position 2 = 17
Branch analysis from position: 11
2 jumps found. (Code = 47) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 37
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 37
Branch analysis from position: 16
Branch analysis from position: 17
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
filename:       /in/UsXPv
function name:  tree
number of ops:  41
compiled vars:  !0 = $data, !1 = $left, !2 = $right, !3 = $tree, !4 = $value, !5 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
          2        RECV_INIT                                        !2      null
    7     3        ASSIGN                                                   !3, <array>
    8     4      > FE_RESET_R                                       $7      !0, ->38
          5    > > FE_FETCH_R                                       ~8      $7, !4, ->38
          6    >   ASSIGN                                                   !5, ~8
    9     7        FETCH_DIM_R                                      ~10     !4, 'lft'
          8        ADD                                              ~11     !1, 1
          9        IS_EQUAL                                         ~12     ~10, ~11
         10      > JMPZ_EX                                          ~12     ~12, ->17
         11    >   TYPE_CHECK                                    2  ~13     !2
         12      > JMPNZ_EX                                         ~13     ~13, ->16
         13    >   FETCH_DIM_R                                      ~14     !4, 'rht'
         14        IS_SMALLER                                       ~15     ~14, !2
         15        BOOL                                             ~13     ~15
         16    >   BOOL                                             ~12     ~13
         17    > > JMPZ                                                     ~12, ->37
   10    18    >   FETCH_DIM_R                                      ~18     !4, 'name'
         19        INIT_ARRAY                                       ~19     ~18, 'name'
         20        FETCH_DIM_W                                      $16     !3, !5
         21        ASSIGN_DIM                                               $16, 'text'
         22        OP_DATA                                                  ~19
   11    23        INIT_FCALL_BY_NAME                                       'tree'
         24        SEND_VAR_EX                                              !0
         25        CHECK_FUNC_ARG                                           
         26        FETCH_DIM_FUNC_ARG                               $22     !4, 'lft'
         27        SEND_FUNC_ARG                                            $22
         28        CHECK_FUNC_ARG                                           
         29        FETCH_DIM_FUNC_ARG                               $23     !4, 'rht'
         30        SEND_FUNC_ARG                                            $23
         31        DO_FCALL                                      0  $24     
         32        FETCH_DIM_W                                      $20     !3, !5
         33        ASSIGN_DIM                                               $20, 'children'
         34        OP_DATA                                                  $24
   12    35        FETCH_DIM_R                                      ~25     !4, 'rht'
         36        ASSIGN                                                   !1, ~25
    8    37    > > JMP                                                      ->5
         38    >   FE_FREE                                                  $7
   15    39      > RETURN                                                   !3
   16    40*     > RETURN                                                   null

End of function tree

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146 ms | 1411 KiB | 20 Q