<nav class="nav_menu">
    <?php 
        foreach($menu as $title => $item) :
    ?>
        <h2><?= $title ?></h2>
        <ul>
            <?php foreach($item as $row) : ?>
                <?php 
                    $uri = $this -> uri -> segment(1);
                    $uri = $uri == '' ? 'home' : $uri;
                    $active = $uri == $row['slug'] ? 'active' : null;
                ?>
                <li class="<?= $active ?>">
                    <a href="<?= site_url($row['slug']) ?>">
                        <i class="<?= $row['icon'] ?>"></i>
                        <span><?= $row['nama'] ?></span>
                    </a>

                    <?php if($row['submenu']) : ?>
                        <ul>
                            <?php foreach($row['submenu'] as $submenu) : ?>
                                <?php 
                                    $uri = $this -> uri -> uri_string();
                                    $active = $uri == $submenu['slug'] ? 'active' : null;
                                ?>
                                <li class="<?= $active ?>">
                                    <a href="<?= site_url($submenu['slug']) ?>">
                                        <span><?= $submenu['nama'] ?></span>
                                    </a>
                                </li>
                            <?php endforeach ?>
                        </ul>
                    <?php endif ?>
                </li> 
            <?php endforeach ?>
        </ul>
    <?php endforeach ?>
</nav>