php - Tree listing for categorys -
i have array this
array ( [0] => stdclass object ( [cat_id] => 3 [cat_name] => sample 3 [cat_description] => [cat_folder] => sample_3 [cat_path] => sample_3 [cat_parent] => 0 [cat_num_files] => 0 [cat_num_files_total] => 0 [cat_user_roles] => [cat_owner] => 1 [cat_icon] => [cat_exclude_browser] => 0 [cat_order] => 0 ) [1] => stdclass object ( [cat_id] => 2 [cat_name] => sample 2 [cat_description] => [cat_folder] => sample_2 [cat_path] => sample_3/sample_2 [cat_parent] => 3 [cat_num_files] => 0 [cat_num_files_total] => 0 [cat_user_roles] => [cat_owner] => 1 [cat_icon] => [cat_exclude_browser] => 0 [cat_order] => 0 ) )
i need list these like
-sample 3 --sample 2 ---sample 4
there no limit link depth, category may have 5 deep, may 10. have tried in foreach
loop failed retrieve list tree.
i recommend recursion, becouse don't know how nested be. bellow example of recursion function.
function gencat($parentcat){ echo $parentcat->name; if ($parentcat->havechildren){ foreach($parentcat->children $child){ gencat($child); } } }
this example, hope helps
Comments
Post a Comment