2014-10-10 102 views
0

这是我的代码造成的偏移量,我找不到原因。未定义的偏移量:6

{ 
    /* menu set up */ 
    $arData = file($this->_sMenuFile); 
    $index = 0; 
    foreach($arData as $line) { 
     //On this line is where the error is happening.               
     list($level,$group,$label,$module,$file,$order,$width) = explode('|',trim($line)); 
     if($level == "top") $sGroup = $label; 
     if(strlen($file) > 0) { 
     $this->_arMenuItems['name'][$index] = $label; 
     $this->_arMenuItems['group'][$index] = $sGroup; 
     $this->_arMenuItems['module'][$index] = $module; 
     $this->_arMenuItems['file'][$index] = $file; 
     $index++; 
    } 
} 
+1

'在此线是其中错误happening.'这意味着有爆炸不具有7个元素返回数组。 – Cheery 2014-10-10 17:26:43

+0

如果不明显,可以在带有爆炸的行之前执行'print_r($ line)',并检查行中有多少个元素。或者,也许只是分隔符不是'|'... – 2014-10-10 17:47:14

回答

0

使用本

if($level == "top") $sGroup = $label; 
    if(strlen($file)-1 > 0) { 
    $this->_arMenuItems['name'][$index] = $label; 
    $this->_arMenuItems['group'][$index] = $sGroup; 
    $this->_arMenuItems['module'][$index] = $module; 
    $this->_arMenuItems['file'][$index] = $file; 
    $index++; 
         } 
}