PHP 数组上的非法字符串偏移警告

PHP Illegal String Offset Warning on Array

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

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

警告正是

"Warning: Illegal string offset 'affixes' in C:\xampp\htdocs\pengakar-master\src\Pengakar.php on line 411"

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

http://ideone.com/QQEdCu

还有一部分没问题。 只有那部分得到错误

感谢您的帮助。

非法偏移意味着您引用的索引不存在。 因此,在这种情况下,从未定义数组的 'affixes' 索引。 为防止错误,更改代码如下:

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

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