【问题标题】:PHP Illegal String Offset Warning on Array数组上的 PHP 非法字符串偏移警告
【发布时间】:2017-01-03 17:49:39
【问题描述】:

我从 if 语句中的数组收到非法字符串偏移警告

411.  if (is_array($attrib['affixes'])) { // merge
412.     $new_affix = array_merge($attrib['affixes'], $new_affix);
413.  }

正是警告是

“警告:C:\xampp\htdocs\pengakar-master\src\Pengakakar.php 中第 411 行的非法字符串偏移 'affixes'”

我在下面插入完整的代码:

http://ideone.com/QQEdCu

另一部分还可以。 只有那部分得到错误

感谢您的帮助。

【问题讨论】:

标签: php arrays string warnings


【解决方案1】:

非法偏移意味着您引用的索引不存在。 因此,在这种情况下,永远不会定义数组的“附加”索引。 为防止出错,将代码更改如下:

if (isset($attrib['affixes']) && is_array($attrib['affixes'])) { // merge
    $new_affix = array_merge($attrib['affixes'], $new_affix);
}

查看此处以获取有关该错误的更多信息: Illegal string offset Warning PHP

【讨论】:

    猜你喜欢
    • 2013-04-11
    • 2012-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-21
    • 1970-01-01
    相关资源
    最近更新 更多