PHP 偏移量错误
我遇到了一个 PHP 错误,通过我在互联网上的所有搜索,我还无法破解该错误。
错误提示:
错误消息 注意:包含()中的未定义偏移量:3(/home/devced/public_html/site/sites/all/themes/cedncsu/page.tpl.php第89行)。
所以,环顾我的代码,我目前有(实际使用评论如下):
<?php
// Get Base URL
global $base_url;
// Get the Page's Parent Menu Item
$menuParent = menu_get_active_trail();
// Since it returns an array, make sure to target what you are looking for
// You should print_r what menu_get_active_trail() to see what else it gives you
$menuParent = $menuParent[1]['link_title'];
$menuParent = strtolower(str_replace( " ", "-", $menuParent));
$menuParent = preg_replace('/[^\w\d_ -]/si', '', $menuParent);
// Generate class specific for department page headers
$menuParentDepartment = menu_get_active_trail();
$menuParentDepartment = $menuParentDepartment[3]['link_title']; // This is where they say the error is
$menuParentDepartment = strtolower(str_replace( " ", "-", $menuParentDepartment));
$menuParentDepartment = preg_replace('/[^\w\d_ -]/si', '', $menuParentDepartment);
// Current Page space replace/lowercase
$currentTitle = strtolower(str_replace( " ", "-", $title));
$currentTitle = preg_replace('/[^\w\d_ -]/si', '', $currentTitle);
?>
我认为这是我所缺少的一般编码实践,但迄今为止一直被困扰。任何帮助将不胜感激。谢谢!
I'm running into a PHP error that through all of my scrummaging around the internet - I have been unable to crack as of yet.
The error says:
Error message
Notice: Undefined offset: 3 in include() (line 89 of /home/devced/public_html/site/sites/all/themes/cedncsu/page.tpl.php).
So, looking around my code, I currently have (actual use commented below):
<?php
// Get Base URL
global $base_url;
// Get the Page's Parent Menu Item
$menuParent = menu_get_active_trail();
// Since it returns an array, make sure to target what you are looking for
// You should print_r what menu_get_active_trail() to see what else it gives you
$menuParent = $menuParent[1]['link_title'];
$menuParent = strtolower(str_replace( " ", "-", $menuParent));
$menuParent = preg_replace('/[^\w\d_ -]/si', '', $menuParent);
// Generate class specific for department page headers
$menuParentDepartment = menu_get_active_trail();
$menuParentDepartment = $menuParentDepartment[3]['link_title']; // This is where they say the error is
$menuParentDepartment = strtolower(str_replace( " ", "-", $menuParentDepartment));
$menuParentDepartment = preg_replace('/[^\w\d_ -]/si', '', $menuParentDepartment);
// Current Page space replace/lowercase
$currentTitle = strtolower(str_replace( " ", "-", $title));
$currentTitle = preg_replace('/[^\w\d_ -]/si', '', $currentTitle);
?>
I think this is a general coding practice that I'm missing, but have thus-far been stumped. Any help would be greatly appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很简单:
$menuParentDepartment[3]
未定义。在尝试对其建立索引之前,您需要确保索引(或 PHP 称之为偏移量)存在。使用isset
。Quite simply:
$menuParentDepartment[3]
is not defined. You need to make sure that the index (or as PHP calls it, offset) exists before you try to index it. Useisset
.