Trying to make menus with categories, sub-categories and sub-sub-categories. Faced a problem - it is impossible to output the result of a nested loop to another div.

Here is the code:

<?php foreach ($categories as $category_1) { ?> <?php if ($category_1['children']) { ?> <li> <a href=""><i class="fa fa-arrow-down"></i>&nbsp;&nbsp;<?php echo $category_1['name']; ?></a> <div class="megamenu"> <div class="col-md-3"> <?php foreach ($category_1['children'] as $category_2) { ?> <a class="child_cat__a" href="<?php echo $category_2['href']; ?>" data-name="<?php echo $category_2['name']; ?>"> <div class="child_cat"><?php echo $category_2['name']; ?></div> </a> <?php foreach($category_2['children'] as $category_3) { ?> <div class="col-md-9" data-name="<?php echo $category_3['name']; ?>"> <a href="<?php echo $category_3['href']; ?>"><span><?php echo $category_3['name']; ?></span></a> </div> <?php } ?> <?php } ?> </div> </div> </li> <?php } ?> <?php } ?> 

Here I have everything that is needed, but in a row.

I wanted to do this:

 <?php foreach ($categories as $category_1) { ?> <?php if ($category_1['children']) { ?> <li> <a href=""><i class="fa fa-arrow-down"></i>&nbsp;&nbsp;<?php echo $category_1['name']; ?></a> <div class="megamenu"> <div class="col-md-3"> <?php foreach ($category_1['children'] as $category_2) { ?> <a class="child_cat__a" href="<?php echo $category_2['href']; ?>" data-name="<?php echo $category_2['name']; ?>"> <div class="child_cat"><?php echo $category_2['name']; ?></div> </a> <?php } ?> </div> <?php foreach($category_2['children'] as $category_3) { ?> <div class="col-md-9" data-name="<?php echo $category_3['name']; ?>"> <a href="<?php echo $category_3['href']; ?>"><span><?php echo $category_3['name']; ?></span></a> </div> <?php } ?> </div> </li> <?php } ?> <?php } ?> 

... but in this case only the very first sub-sub-category is displayed.

Immediately I apologize for the Nubian question, and at least I can suggest how you can display the result in a separate div in a tpl file from a nested loop.

Thank you in advance )

    0