致命错误:不能使用 stdClass 类型的对象作为数组 [英] Fatal error: Cannot use object of type stdClass as array in
本文介绍了致命错误:不能使用 stdClass 类型的对象作为数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到错误:
第 183 行致命错误:无法使用 stdClass 类型的对象作为数组"
"Fatal error: Cannot use object of type stdClass as array in" on line 183
来自此代码:
$getvidids = $ci->db->query(
"SELECT * FROM videogroupids " .
"WHERE videogroupid='$videogroup' AND used='0' LIMIT 10");
foreach ($getvidids->result() as $row){
$vidid = $row['videoid']; //This is line 183
}
有人知道上面的代码有什么问题吗?或者这个错误是什么意思?
Anyone know what's wrong with the above code? Or what this error means?
推荐答案
CodeIgniter 将结果行作为对象而不是数组返回.来自用户指南:
CodeIgniter returns result rows as objects, not arrays. From the user guide:
此函数以对象数组或失败时空数组的形式返回查询结果.
result()
This function returns the query result as an array of objects, or an empty array on failure.
您必须使用以下符号访问字段:
You'll have to access the fields using the following notation:
foreach ($getvidids->result() as $row) {
$vidid = $row->videoid;
}
这篇关于致命错误:不能使用 stdClass 类型的对象作为数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文