douli0531 2016-08-06 17:38
浏览 13

PHP与阵列的多级菜单(新)

I don't know if it's authorize (sorry if not), but this post follow this link Multi level menu with PHP with array

I rewrited the code like this because iterator doesn't work in my case , I think. I tried to create an automatic menu, but I have a problem to display array who begin at apps1

Idea ? Thank you

my array

  $cl_box_groups[] = array(
                          'level_title' => BOX_HEADING_CONFIGURATION,
                          'level_class' => 'fa fa-sun-o',

                          'apps' => array(
                            array(
                              'level_title' => MENU_CONFIGURATION_STORE,
                              'level_class' => 'fa fa-sun-o'
                            ),

                            'apps1' => array (
                              array('level_title' => MENU_CONFIGURATION_GENERAL,
                                    'level_class' => '',
                                    'level_link' => 'configuration.php?gID=1',
                              ),
                              array('level_title' => MENU_CONFIGURATION_LEGACY,
                                    'level_class' => '',
                                    'level_link' => 'configuration.php?gID=25',
                              ),
                            ),
                          ),
                          );

But with this code, I have all result but If I apply it in my html, it doesn't work for apps1

 echo '<pre>';
  foreach ($cl_box_groups as $groups) {
    print_r($groups);
    foreach($groups['apps'] as $app) {
      print_r($app);
      foreach($app['apps1'] as $apps1) {
        print_r($apps1);
      }
    }
  }
echo '</pre>';

result

<pre>Array
(
    [level_title] => Configuration
    [level_class] => fa fa-sun-o
    [apps] => Array
        (
            [0] => Array
                (
                    [level_title] => Ma boutique
                    [level_class] => fa fa-sun-o
                )

            [apps1] => Array
                (
                    [0] => Array
                        (
                            [level_title] => Configuration générale
                            [level_class] => 
                            [level_link] => configuration.php?gID=1
                        )

                    [1] => Array
                        (
                            [level_title] => Législation réglementaire
                            [level_class] => 
                            [level_link] => configuration.php?gID=25
                        )

                )

        )

)
Array
(
    [level_title] => Ma boutique
    [level_class] => fa fa-sun-o
)
Array
(
    [0] => Array
        (
            [level_title] => Configuration générale
            [level_class] => 
            [level_link] => configuration.php?gID=1
        )

    [1] => Array
        (
            [level_title] => Législation réglementaire
            [level_class] => 
            [level_link] => configuration.php?gID=25
        )

)
</pre>

Now for my menu

          <div id="menu">
            <nav>
              <h2><i class="fa fa-reorder"></i>Admin</h2>
              <ul>
                <a href="../index.php" target="_blank"><?php echo HEADER_TITLE_ONLINE_CATALOG; ?></a>
<?php
  foreach ($cl_box_groups as $groups) {
?>
                <li>
                  <a href="#"><i class="<?php echo $groups['level_class']; ?>"></i><?php echo $groups['level_title']; ?></a>
                  <h2><i class="<?php echo $groups['level_class']; ?>"></i><?php echo $groups['level_title']; ?></h2>
                  <ul>
                    <h2><i class="<?php echo $groups['level_class']; ?>"></i><?php echo $groups['level_title']; ?></h2>
<?php

    foreach ($groups['apps'] as $app) {
?>
                    <li>
                      <a href="#"><i class="<?php echo $app['level_class']; ?>"></i><?php echo $app['level_title']; ?></a>
                      <h2><i class="<?php echo $groups['level_class']; ?>"></i><?php echo $groups['level_title']; ?></h2>
                      <ul>
                        <li>
                          <h2><i class="<?php echo $app['level_class']; ?>"></i><?php echo $app['level_title']; ?></h2>
                        </li>
                        <ul>
<?php
      foreach ($app['apps1'] as $apps1) {
?>
                          <li>
                            <a href="<?php echo $apps1['level_link']; ?>"><?php echo $apps1['level_title']; ?></a>
                          </li>
<?php
      }

?>
                        </ul>
                      </ul>
                    </li>
<?php
    }

?>

                  </ul>
                </li>
<?php
  }
?>
              </ul>
            </nav>
          </div>

Result

  <div id="menu">
    <nav>
      <h2><i class="fa fa-reorder"></i>Admin</h2>
      <ul>
        <a href="../index.php" target="_blank">Catalogue en ligne</a>
        <li>
          <a href="#"><i class="fa fa-sun-o"></i>Configuration</a>
          <h2><i class="fa fa-sun-o"></i>Configuration</h2>
          <ul>
            <h2><i class="fa fa-sun-o"></i>Configuration</h2>
            <li>
              <a href="#"><i class="fa fa-sun-o"></i>Ma boutique</a>
              <h2><i class="fa fa-sun-o"></i>Configuration</h2>
              <ul>
                <li>
                  <h2><i class="fa fa-sun-o"></i>Ma boutique</h2>
                </li>
                <ul>
                </ul>
              </ul>
            </li>
            <li>
              <a href="#"><i class=""></i></a>
              <h2><i class="fa fa-sun-o"></i>Configuration</h2>
              <ul>
                <li>
                  <h2><i class=""></i></h2>
                </li>
                <ul>
                </ul>
              </ul>
            </li>

          </ul>
        </li>
      </ul>
    </nav>
  </div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 关于大棚监测的pcb板设计
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用