Undefined offset error, but offset is not undefined

て烟熏妆下的殇ゞ 提交于 2019-12-05 13:35:48

Do

var_dump($entries_found);

To check that the array does indeed have an offset of zero. Other things you can try would be reseting the array pointer

reset($entries_found);

of checking if it's set first

if (isset($entries_found[0]['member'])) // do things

If all else fails you could just supress the notice with

$members = @$entries_found[0]['member'];

I don't really know what happens with your $entries_found before accessing it from get_members

But i had the same problem. print_r and var_dump showed me, that the index exists but when i tried to access it i got the offset error

In my case i decoded a json string with json_decode without setting the assoc flag.

// Not working
$assocArray = json_decode('{"207":"sdf","210":"sdf"}');
echo $assocArray[207];


// working witht the assoc flag set
$assocArray = json_decode('{"207":"sdf","210":"sdf"}', true);
echo $assocArray[207];

Got my solution from here: Undefined offset while accessing array element which exists

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!