3v4l.org

run code in 300+ PHP versions simultaneously
<?php $category = [ [ 'sort_id' => 11, 'sort_name' => '一级目录', 'sort_child' => 0 ], [ 'sort_id' => 12, 'sort_name' => '二级目录', 'sort_child' => 11 ], [ 'sort_id' => 13, 'sort_name' => '二级目录', 'sort_child' => 11 ], [ 'sort_id' => 14, 'sort_name' => '三级目录', 'sort_child' => 13 ], [ 'sort_id' => 15, 'sort_name' => '三级目录', 'sort_child' => 13 ], [ 'sort_id' => 16, 'sort_name' => '三级目录', 'sort_child' => 13 ], [ 'sort_id' => 17, 'sort_name' => '一级目录2', 'sort_child' => 0 ], [ 'sort_id' => 18, 'sort_name' => '三级目录', 'sort_child' => 12 ], [ 'sort_id' => 19, 'sort_name' => '三级目录', 'sort_child' => 12 ] ]; $newCategory = []; processCategory($category, 0, $newCategory); $leave = 0; foreach ($newCategory as $currentCategory) { echo $currentCategory['sort_name']; } function processCategory(&$category, $parrentId, &$newCategory) { foreach ($category as $currentCategory) { if ($currentCategory['sort_child'] != $parrentId) continue; array_push($newCategory, $currentCategory); processCategory( $category, $currentCategory['sort_id'], $newCategory ); } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 13
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 13
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/KQ8dM
function name:  (null)
number of ops:  15
compiled vars:  !0 = $category, !1 = $newCategory, !2 = $leave, !3 = $currentCategory
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   50     1        ASSIGN                                                   !1, <array>
   52     2        INIT_FCALL_BY_NAME                                       'processCategory'
          3        SEND_VAR_EX                                              !0
          4        SEND_VAL_EX                                              0
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0          
   54     7        ASSIGN                                                   !2, 0
   55     8      > FE_RESET_R                                       $8      !1, ->13
          9    > > FE_FETCH_R                                               $8, !3, ->13
   56    10    >   FETCH_DIM_R                                      ~9      !3, 'sort_name'
         11        ECHO                                                     ~9
   55    12      > JMP                                                      ->9
         13    >   FE_FREE                                                  $8
   70    14      > RETURN                                                   1

Function processcategory:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 21
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 21
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/KQ8dM
function name:  processCategory
number of ops:  23
compiled vars:  !0 = $category, !1 = $parrentId, !2 = $newCategory, !3 = $currentCategory
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   61     3      > FE_RESET_R                                       $4      !0, ->21
          4    > > FE_FETCH_R                                               $4, !3, ->21
   62     5    >   FETCH_DIM_R                                      ~5      !3, 'sort_child'
          6        IS_NOT_EQUAL                                             !1, ~5
          7      > JMPZ                                                     ~6, ->9
   63     8    > > JMP                                                      ->4
   65     9    >   INIT_FCALL                                               'array_push'
         10        SEND_REF                                                 !2
         11        SEND_VAR                                                 !3
         12        DO_ICALL                                                 
   66    13        INIT_FCALL_BY_NAME                                       'processCategory'
   67    14        SEND_VAR_EX                                              !0
         15        CHECK_FUNC_ARG                                           
         16        FETCH_DIM_FUNC_ARG                               $8      !3, 'sort_id'
         17        SEND_FUNC_ARG                                            $8
         18        SEND_VAR_EX                                              !2
         19        DO_FCALL                                      0          
   61    20      > JMP                                                      ->4
         21    >   FE_FREE                                                  $4
   70    22      > RETURN                                                   null

End of function processcategory

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.54 ms | 1400 KiB | 15 Q