php 数组使未定义索引:0 通知消失
是的,所以我打开了 E_NOTICES 并且我的代码可以正常工作,只是每次我尝试使用设置键将数据插入数组时,我都会不断收到“严重性:通知消息:未定义索引:0”。当你尝试调试时,这真的很烦人。
我做错了什么,会导致通知消失而不关闭 E_NOTICES?
foreach ($bracketmatches->result() as $row)
{
if(!isset($bracketdata[$row->position]))
{
$bracketdata[$row->position] = array();
}
$bracketdata[$row->position] = array("home_name" => $teams[$row->home_id]['team_name']);
}
Right so i have E_NOTICES on and my code works its just i keep getting "Severity: Notice Message: Undefined index: 0" everytime i try to insert my data into the array with the set key. Its really annoying when ur trying to debug.
What am i doing wrong that will make the notices go away without turning off E_NOTICES?
foreach ($bracketmatches->result() as $row)
{
if(!isset($bracketdata[$row->position]))
{
$bracketdata[$row->position] = array();
}
$bracketdata[$row->position] = array("home_name" => $teams[$row->home_id]['team_name']);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
$teams[$row->home_id]
是否已明确定义?编辑:为您进行快速而肮脏的测试:
Is
$teams[$row->home_id]
definitely defined?edit: Quick and dirty test for you:
如果没有更多信息,不可能确定,但我会检查 $row->position 是否已设置,并且 $row->home_id 是否已设置(如果它们可能未定义)。
Impossible to say for certain without more information, but I would check that $row->position is set and that $row->home_id is set if there is any possibility they may be undefined.
您必须先初始化基本数组,然后再将值推入其中。这里的 isset 并没有真正做任何事情。把它扔掉吧。如果仍然出现错误,请确保始终设置
$teams[$row->home_id]['team_name']
。You must initialize the base array before pushing values to it. The isset here doesn't really do anything. Just throw it away. If you still get the error make sure
$teams[$row->home_id]['team_name']
is always set.