3v4l.org

run code in 300+ PHP versions simultaneously
<?php // I have a table `categoreis` to store products' categories information // it use categories_id and parent_id to identify the level relationship between those categories // now I want a function(tep_get_leaf_categories() below) to get all leaf categories for a passed in category_id // say tep_get_leaf_categories(360) will get all leaf categories id as an array of category 360 // this function get all subcategories, or child-categories for $category_id function tep_get_subcategories($category_id) { $subcategories_raw = tep_db_query('SELECT ca.categories_id FROM categories ca LEFT JOIN categoreis cb ON ca.parent_id = cb.categories_id WHERE cb.categoreis_id = ' . (int) $category_id); $subcategories = array(); if (mysql_num_rows($subcategories_raw) >= 1) { while ($row = mysql_fetch_assoc($subcategories_raw)) { $category_id = $row['categories_id']; $subcategories[] = $category_id; } } return $subcategories; } // this is the function that I'm working on, to get the leaf category of $category_id function tep_get_leaf_categories($category_id, &$result = array()) { $sub_categories = tep_get_subcategories($category_id); // no sub categories found:return self as result if (count($sub_categories) === 0) { $result[] = $category_id; } else { foreach ($sub_categories as $category_id) { tep_get_leaf_categories($category_id, $result); } } return $result; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/b4Bp8
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E > > RETURN                                                   1

Function tep_get_subcategories:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 23
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 14
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 14
Branch analysis from position: 23
Branch analysis from position: 14
Branch analysis from position: 23
filename:       /in/b4Bp8
function name:  tep_get_subcategories
number of ops:  25
compiled vars:  !0 = $category_id, !1 = $subcategories_raw, !2 = $subcategories, !3 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
    9     1        INIT_FCALL_BY_NAME                                       'tep_db_query'
   13     2        CAST                                          4  ~4      !0
          3        CONCAT                                           ~5      'SELECT+ca.categories_id%0A%09%09%09%09%09%09%09FROM+categories+ca%0A%09%09%09%09%09%09%09LEFT+JOIN+categoreis+cb%0A%09%09%09%09%09%09%09%09ON+ca.parent_id+%3D+cb.categories_id%0A%09%09%09%09%09%09%09WHERE+cb.categoreis_id+%3D+', ~4
          4        SEND_VAL_EX                                              ~5
          5        DO_FCALL                                      0  $6      
    9     6        ASSIGN                                                   !1, $6
   15     7        ASSIGN                                                   !2, <array>
   16     8        INIT_FCALL_BY_NAME                                       'mysql_num_rows'
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0  $9      
         11        IS_SMALLER_OR_EQUAL                                      1, $9
         12      > JMPZ                                                     ~10, ->23
   17    13    > > JMP                                                      ->18
   18    14    >   FETCH_DIM_R                                      ~11     !3, 'categories_id'
         15        ASSIGN                                                   !0, ~11
   19    16        ASSIGN_DIM                                               !2
         17        OP_DATA                                                  !0
   17    18    >   INIT_FCALL_BY_NAME                                       'mysql_fetch_assoc'
         19        SEND_VAR_EX                                              !1
         20        DO_FCALL                                      0  $14     
         21        ASSIGN                                           ~15     !3, $14
         22      > JMPNZ                                                    ~15, ->14
   23    23    > > RETURN                                                   !2
   24    24*     > RETURN                                                   null

End of function tep_get_subcategories

Function tep_get_leaf_categories:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 12
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 19
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 19
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/b4Bp8
function name:  tep_get_leaf_categories
number of ops:  22
compiled vars:  !0 = $category_id, !1 = $result, !2 = $sub_categories
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
   28     2        INIT_FCALL                                               'tep_get_subcategories'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $3      
          5        ASSIGN                                                   !2, $3
   31     6        COUNT                                            ~5      !2
          7        IS_IDENTICAL                                             ~5, 0
          8      > JMPZ                                                     ~6, ->12
   32     9    >   ASSIGN_DIM                                               !1
         10        OP_DATA                                                  !0
         11      > JMP                                                      ->20
   34    12    > > FE_RESET_R                                       $8      !2, ->19
         13    > > FE_FETCH_R                                               $8, !0, ->19
   35    14    >   INIT_FCALL_BY_NAME                                       'tep_get_leaf_categories'
         15        SEND_VAR_EX                                              !0
         16        SEND_VAR_EX                                              !1
         17        DO_FCALL                                      0          
   34    18      > JMP                                                      ->13
         19    >   FE_FREE                                                  $8
   39    20    > > RETURN                                                   !1
   40    21*     > RETURN                                                   null

End of function tep_get_leaf_categories

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.03 ms | 1403 KiB | 14 Q