2014-02-17 94 views
-2

我我得到`注意:未定義指數:index.php文件

公告:未定義的索引:在的index.php在線26

XXXXX /的index.php當我刪除了menu.php中的$ submenu變量數組。一切工作正常,但是當我添加$ submenu數組變量時,我收到錯誤消息。 ` 什麼我想在這裏做的就是頂層,然後搜索,如果他們任何一個孩子submneu

在index.php文件,我有這樣的代碼

foreach($menu as $menu){ 
      $title = $menu[0]; 
      $privllages = $menu[1]; 
      $template = $menu[2]; 
      $class = $menu[3]; 
      $id = $menu[4]; 
      $icon = $menu[5]; 

      if(!$title){$title = 'No Title';} 
      if($class){$class = 'class="'.$class.'"';} else {$class = '';} 
      if($id){$id = 'id="'.$id.'"';} else {$id = '';} 
      if(!$icon){$icon = "menu-default.png";} 

      echo '<a href="'.$template.'" '.$class.' '.$id.'>' . $title . '</a>' . "<br/>"; 

/* LINE 26 Starts here */ 
       if($submenu[$template]){ 
        foreach($submenu[$template] as $submenu){ 
         echo '<a href="#">' . $submenu[0] . '</a>' . "<br/>"; 
        } 
       } 
     } 

在menu.php文件

$menu[1] = array('Dashboard', '0', 'index.php', 'sidebar-menu','','menu-dashboard'); 
$menu[2] = array('Pages', '0', 'pages.php', 'sidebar-menu','','menu-dashboard'); 
$menu[3] = array('Media', '0', 'media.php', 'sidebar-menu','','menu-dashboard'); 
$menu[4] = array('Tools', '0', 'tools.php', 'sidebar-menu','','menu-dashboard'); 
$menu[5] = array('Users', '0', 'users.php', 'sidebar-menu','','menu-dashboard'); 
$menu[6] = array('Settings', '0', 'settings.php', 'sidebar-menu','','menu-dashboard'); 

$submenu['pages.php'][1] = array('All Links 1', 'admin-menu', 'manage_links', 'link-manager.php'); 
$submenu['pages.php'][2] = array('All Links 2', 'admin-menu', 'manage_links', 'link-manager.php'); 
$submenu['pages.php'][3] = array('All Links 3', 'admin-menu', 'manage_links', 'link-manager.php'); 
$submenu['pages.php'][4] = array('All Links 4', 'admin-menu', 'manage_links', 'link-manager.php'); 
+1

您示例中的哪一行是26? –

+0

您好我已編輯的問題評論/ * LINE 26從這裏開始*/ – user3140617

+1

而不是'if($ submenu [$ template]){'try' if(array_key_exists($ template,$ submenu)){' –

回答

3

而不是

if($submenu[$template]){ 

使用

if(!empty($submenu[$template])){ 

這如果$子菜單[$模板]存在,並且不爲空

+0

哦,是的,這是它。有用!真棒 – user3140617

1

嘗試用這個修改後的代碼將僅觸發。錯誤在代碼中提到

<?php 
$menu[1] = array('Dashboard', '0', 'index.php', 'sidebar-menu','','menu-dashboard'); 
$menu[2] = array('Pages', '0', 'pages.php', 'sidebar-menu','','menu-dashboard'); 
$menu[3] = array('Media', '0', 'media.php', 'sidebar-menu','','menu-dashboard'); 
$menu[4] = array('Tools', '0', 'tools.php', 'sidebar-menu','','menu-dashboard'); 
$menu[5] = array('Users', '0', 'users.php', 'sidebar-menu','','menu-dashboard'); 
$menu[6] = array('Settings', '0', 'settings.php', 'sidebar-menu','','menu-dashboard'); 

$submenu['pages.php'][1] = array('All Links 1', 'admin-menu', 'manage_links', 'link-manager.php'); 
$submenu['pages.php'][2] = array('All Links 2', 'admin-menu', 'manage_links', 'link-manager.php'); 
$submenu['pages.php'][3] = array('All Links 3', 'admin-menu', 'manage_links', 'link-manager.php'); 
$submenu['pages.php'][4] = array('All Links 4', 'admin-menu', 'manage_links', 'link-manager.php'); 

foreach($menu as $arr_menu){ // problem-1 was here foreach($menu as $menu) 
     $title = $arr_menu[0]; 
     $privllages = $arr_menu[1]; 
     $template = $arr_menu[2]; 
     $class = $arr_menu[3]; 
     $id = $arr_menu[4]; 
     $icon = $arr_menu[5]; 

     if(!$title){$title = 'No Title';} 
     if($class){$class = 'class="'.$class.'"';} else {$class = '';} 
     if($id){$id = 'id="'.$id.'"';} else {$id = '';} 
     if(!$icon){$icon = "menu-default.png";} 

     echo '<a href="'.$template.'" '.$class.' '.$id.'>' . $title . '</a>' . "<br/>"; 
      if(isset($submenu[$template])){ // problem-2 was here not checking isset 
       foreach($submenu[$template] as $arr_submenu){ // problem-3 was here foreach($submenu as $submenu) 
        echo '<a href="#">' . $arr_submenu[0] . '</a>' . "<br/>"; 
       } 
      } 
    } 
?> 
1

變化

if($submenu[$template]) 

if(!empty($submenu[$template])) 

而且下面一行是模糊

foreach($menu as $menu) 

改變它像

foreach($menu as $my_menu)