Tree listing for categorys

I have an array like 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
    )
  [2] => stdClass Object
    (
        [cat_id] => 4
        [cat_name] => sample 4
        [cat_description] => 
        [cat_folder] => sample_4
        [cat_path] => sample_2/sample_4
        [cat_parent] => 2
        [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 is no limit for the link depth may be 1 category have 5 depth level may be 10. Am tried this in foreach loop but failed to list like a tree.


Source: wordpress

Leave a Reply