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)) { $child = []; $child['text'] = ['name' => $value['name']]; $childTree = tree($data, $value['lft'], $value['rht']); if (!empty($childTree)) { $child['children'] = $childTree; } $tree[] = $child; $left = $value['rht']; } } return $tree; } $tree = tree(json_decode($category, true))[0]; 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/AYCGt
function name:  (null)
number of ops:  19
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>
   23     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        FETCH_DIM_R                                      ~7      $6, 0
         10        ASSIGN                                                   !2, ~7
   25    11        INIT_FCALL                                               'print_r'
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                                 
   27    14        INIT_FCALL                                               'json_encode'
         15        SEND_VAR                                                 !2
         16        DO_ICALL                                         $10     
         17        ECHO                                                     $10
         18      > RETURN                                                   1

Function tree:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 43
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 43
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 = 42
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 38
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 38
Branch analysis from position: 42
Branch analysis from position: 16
Branch analysis from position: 17
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 43
filename:       /in/AYCGt
function name:  tree
number of ops:  46
compiled vars:  !0 = $data, !1 = $left, !2 = $right, !3 = $tree, !4 = $value, !5 = $key, !6 = $child, !7 = $childTree
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                                       $9      !0, ->43
          5    > > FE_FETCH_R                                       ~10     $9, !4, ->43
          6    >   ASSIGN                                                   !5, ~10
    9     7        FETCH_DIM_R                                      ~12     !4, 'lft'
          8        ADD                                              ~13     !1, 1
          9        IS_EQUAL                                         ~14     ~12, ~13
         10      > JMPZ_EX                                          ~14     ~14, ->17
         11    >   TYPE_CHECK                                    2  ~15     !2
         12      > JMPNZ_EX                                         ~15     ~15, ->16
         13    >   FETCH_DIM_R                                      ~16     !4, 'rht'
         14        IS_SMALLER                                       ~17     ~16, !2
         15        BOOL                                             ~15     ~17
         16    >   BOOL                                             ~14     ~15
         17    > > JMPZ                                                     ~14, ->42
   10    18    >   ASSIGN                                                   !6, <array>
   11    19        FETCH_DIM_R                                      ~20     !4, 'name'
         20        INIT_ARRAY                                       ~21     ~20, 'name'
         21        ASSIGN_DIM                                               !6, 'text'
         22        OP_DATA                                                  ~21
   12    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        ASSIGN                                                   !7, $24
   13    33        ISSET_ISEMPTY_CV                                 ~26     !7
         34        BOOL_NOT                                         ~27     ~26
         35      > JMPZ                                                     ~27, ->38
   14    36    >   ASSIGN_DIM                                               !6, 'children'
         37        OP_DATA                                                  !7
   16    38    >   ASSIGN_DIM                                               !3
         39        OP_DATA                                                  !6
   17    40        FETCH_DIM_R                                      ~30     !4, 'rht'
         41        ASSIGN                                                   !1, ~30
    8    42    > > JMP                                                      ->5
         43    >   FE_FREE                                                  $9
   20    44      > RETURN                                                   !3
   21    45*     > RETURN                                                   null

End of function tree

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.01 ms | 1411 KiB | 20 Q