未定义的偏移错误,但偏移量不是未定义的
我得到:
Notice: Undefined offset: 0
在我的代码中,但是我可以 print_r 我试图获取的元素及其明确定义的。
function get_members($entries_found) {
$members = $entries_found[0]['member'];
...
}
如果我 print_r($members) 我得到预期的输出,但是我仍然收到通知。
有什么线索吗?
I'm getting:
Notice: Undefined offset: 0
in my code, however I can print_r the element I am trying to get and its clearly defined.
function get_members($entries_found) {
$members = $entries_found[0]['member'];
...
}
If I print_r($members) I get the expected output, however I'm still getting the Notice.
Any clues?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
检查
数组的偏移量是否确实为零。您可以尝试的其他方法是重置数组指针,
检查它是否首先设置
如果所有其他方法都失败,您可以使用以下命令来抑制通知
Do
To check that the array does indeed have an offset of zero. Other things you can try would be reseting the array pointer
of checking if it's set first
If all else fails you could just supress the notice with
在从
get_members
访问您的$entries_found
之前,我真的不知道它会发生什么,但我也遇到了同样的问题。
print_r
和var_dump
向我展示了索引存在,但是当我尝试访问它时,我收到了offset error
在我的例子中,我解码了一个 json带有
json_decode
的字符串,而不设置assoc
标志。从这里得到了我的解决方案: 访问存在的数组元素时未定义偏移
I don't really know what happens with your
$entries_found
before accessing it fromget_members
But i had the same problem.
print_r
andvar_dump
showed me, that the index exists but when i tried to access it i got theoffset error
In my case i decoded a json string with
json_decode
without setting theassoc
flag.Got my solution from here: Undefined offset while accessing array element which exists