foreach之后,菜单和子菜单会重复出现。
我使用Codeigniter和MySql开发仪表板。现在,我尝试创建动态菜单和子菜单,但是所有菜单和子菜单重复两次。结果出乎意料。
<div class="menu">
<ul class="list">
<!-- Menu Looping -->
<?php foreach ($menu as $m) : ?>
<li class="header">
<?= $m['menu']; ?>
</li>
<!-- SubMenu Looping -->
<?php foreach ($subMenu as $sm) : ?>
<?php if ($sm['is_collapse'] == 0) : ?>
<li>
<a href="<?= base_url($sm['url']); ?>">
<i class="material-icons"><?= $sm['icon']; ?></i>
<span><?= $sm['title']; ?></span>
</a>
</li>
<?php else : ?>
<?php foreach ($subMenu as $sm) : ?>
<li>
<a href="javascript:void(0);" class="menu-toggle">
<i class="material-icons"><?= $sm['icon']; ?></i>
<span><?= $sm['title']; ?></span>
</a>
<?php foreach ($subMenuItem as $smi) : ?>
<ul class="ml-menu">
<?php if ($smi['sub_menu_title'] == $sm['title']) : ?>
<li>
<a href="<?= base_url($smi['url']); ?>"><?= $smi['title']; ?></a>
</li>
<?php endif; ?>
</ul>
<?php endforeach; ?>
</li>
<?php endforeach; ?>
<?php endif; ?>
<?php endforeach; ?>
<?php endforeach; ?>
</ul>
</ul>
</div>