On Thu, Aug 16, 2012 at 12:40 PM, Tristan <sunnrunner@xxxxxxxxx> wrote: > I can't for the life of me figure out how to find the depth of the array > that I'm looping through to output tabs or indentations to the display for > each depth. The entries also have section postition if you can figure out > how to include that within each depth of the results I will buy you a case > of beer. > > I was hoping to do something like... > > foreach($trees as $tree){ > if($tree['current_depth'] == 0){ > echo $tree['menu_item']; > } else if($tree['current_depth'] == 1){ > echo 'indentation'.$tree['menu_item']; > } else if($tree['current_depth'] == 2){ > echo 'indentation - indentation'.$tree['menu_item']; > } > } > > > Or maybe even like this... > > foreach($trees as $tree){ > // output the amount of times current_depth equals > echo str_repeat(" ", $tree['current_depth']) > } > > I have my $tree structure as: > > [16] => Array > ( > [section_id] => 21 > [section_parent_id] => 0 > [section_pos] => 30 > [section_name] => Resource Center > [has_order] => 1 > [section_has_hierarchy] => 1 > [total_entries] => 35 > [children] => Array > ( > [0] => Array > ( > [section_id] => 38 > [section_parent_id] => 21 > [section_pos] => 31 > [section_name] => Resource Center > [has_order] => 1 > [section_has_hierarchy] => 1 > [total_entries] => 35 > [children] => Array > > ( > [0] => Array > ( > [section_id] => 39 > [section_parent_id] => 38 > [section_pos] => 32 > [section_name] => Resource Center > [has_order] => 1 > [section_has_hierarchy] => 1 > [total_entries] => 35 > ) > > [1] => Array > ( > [section_id] => 40 > [section_parent_id] => 38 > [section_pos] => 33 > [section_name] => Resource Center > [has_order] => 1 > [section_has_hierarchy] => 1 > [total_entries] => 35 > ) > ) > > > > > [19] => Array > ( > [section_id] => 26 > [section_parent_id] => 0 > [section_pos] => 45 > [section_name] => Resource Center > [has_order] => 1 > [section_has_hierarchy] => 1 > [total_entries] => 55 > [children] => Array > ( > [0] => Array > ( > [section_id] => 27 > [section_parent_id] => 26 > [section_pos] => 46 > [section_name] => Newsletters Intro > [has_order] => 0 > [section_has_hierarchy] => 1 > [total_entries] => 1 > ) > > ) > > ) > maybe something like this in the foreach if parent = 0 then level = 0; if haschilden is true increment level;