PHP错误Cannot use object of type stdClass as array in错误的解决办法_php技巧
程序员文章站
2022-03-29 14:57:32
...
很多人在PHP输出一个二维数组的时候出现“Fatal error: Cannot use object of type stdClass as array in……”。
解决办法分析如下:
解决办法分析如下:
现有这样一个二维数组:
复制代码 代码如下:
Array (
[0] => stdClass Object (
[id] => 1
[title] => 招聘信息
[size] => 300*150
[pic] => ./upload/20140602093535.jpg
[state] => 0 )
[1] => stdClass Object (
[id] => 2
[title] => 首页头条
[size] => 300*150
[pic] => ./upload/20140602093443.jpg
[state] => 0 )
)
[0] => stdClass Object (
[id] => 1
[title] => 招聘信息
[size] => 300*150
[pic] => ./upload/20140602093535.jpg
[state] => 0 )
[1] => stdClass Object (
[id] => 2
[title] => 首页头条
[size] => 300*150
[pic] => ./upload/20140602093443.jpg
[state] => 0 )
)
输出开始写的方法是:$pic[0][title]
结果就出现上面的错误。
其实,数组中是返回的是一个对象,不能直接用[]来显示,正确的输出方法是:$pic[0]->title
问题解决!
上一篇: php网页乱码
下一篇: php如何防止form重复提交
推荐阅读
-
PHP错误Cannot use object of type stdClass as array in错误的解决办法
-
PHP JSON出错:Cannot use object of type stdClass as array解决方法
-
PHP“Cannot use object of type stdClass as array”
-
PHP Fatal error: Cannot use object of type stdClass as array in错误_PHP教程
-
PHP JSON出错:Cannot use object of type stdClass as array解决方法,jsonstdclass_PHP教程
-
PHP JSON出错:Cannot use object of type stdClass as array解决方法
-
Cannot use object of type stdClass as array_PHP教程
-
PHP JSON出错:Cannot use object of type stdClass as array解决方法,jsonstdclass
-
PHP错误Cannot use object of type stdClass as array in错误的解决办法
-
php下关于Cannot use a scalar value as an array的解决办法_php技巧