У меня есть эта структура данных в моем массиве $ category
stdClass Object
(
[37] => Array
(
[term_id] => 37
[name] => Files
[parent] => 0
[38] => Array
(
[term_id] => 38
[name] => Downloads
[parent] => 37
)
)
[29] => Array
(
[term_id] => 29
[name] => Articles
[parent] => 0
[36] => Array
(
[term_id] => 36
[name] => General
[parent] => 29
)
[35] => Array
(
[term_id] => 35
[name] => WordPress
[parent] => 29
)
[34] => Array
(
[term_id] => 34
[name] => Php, Sql
[parent] => 29
)
)
[1] => Array
(
[term_id] => 1
[name] => Uncategorized
[parent] => 0
)
)
Теперь мне нравится печатать эти данные в следующей форме с отступами.
Files
Downloads
Articles
General
WordPress
Php, Sql
Uncategorized
Для достижения вышеуказанного результата я использую этот код
$categories = get_array_content(); // Return the above data
print_category_tree($categories);
function print_category_tree(&$c)
{
foreach($c as $cat)
{
?>
<label>
<input type="checkbox" value="<?php echo $cat['term_id']; ?>" /> <?php echo $cat['name']; ?>
</label>
<br />
<?php
foreach($cat as $categ)
{
if(is_array($categ))
{
print_category_tree($categ);
}
}
}
}
Я знаю, что с этим что-то не так, но не могу догадаться, что. Может кто-нибудь помочь мне с итерацией многомерного массива?