PHP 偏移量错误

发布于 2024-12-20 00:31:03 字数 1349 浏览 1 评论 0原文

我遇到了一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2024-12-27 00:31:03

很简单:$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. Use isset.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文