function Tree($categories, $depth = -1) { $depth++; foreach ($categories as $category) { $pre = '❱'; if ($it == 0) { $div = '<div id="category_collapse' . $category->prime . '"'; if ($category->prime != -1) { $div .= 'class=collapse'; } $div .= '>'; echo $div; } $it++; ?> <a href="#category_collapse<?php echo $category->id; ?> " class="accordion-toggle list-group-item" data-toggle="collapse" data-parent="#category_accordion" style="padding-left:<?php echo 15 + $depth * 15; ?> px;">❱ <?php echo $category->name; ?> <span class="badge text-align-right"><?php echo $category->subcategory_count; ?> </span></a> <?php Tree($category->categories, $depth); if ($it == count($categories)) { echo '</div>'; $it = 0; } } }
function Tree($data, $path = '') { $out = array(); foreach ($data as $key => $val) { $idx = "{$path}/{$key}"; if (is_array($val)) { $out[$idx] = Tree($val, "{$path}/{$key}"); } else { $out[$idx] = $val; } } return $out; }