Home >Backend Development >PHP Tutorial >PHP Cannot use object of type stdClass as array in error solution

PHP Cannot use object of type stdClass as array in error solution

不言
不言Original
2018-06-08 15:33:2815707browse

This article mainly introduces the solution to the PHP error Cannot use object of type stdClass as array in error. It has certain reference value. Now I share it with you. Friends in need can refer to it

Many people get "Fatal error: Cannot use object of type stdClass as array in..." when PHP outputs a two-dimensional array. This article mainly introduces the solution to this error. Friends who need it can refer to it

Many people appear "Fatal error: Cannot use object of type stdClass as array in..." when PHP outputs a two-dimensional array. …”.
The solution analysis is as follows:

There is such a two-dimensional array:

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 ) 
 )

The method to start writing the output is: $pic[0][title]

As a result, the above error occurs.

Actually, an object is returned in the array and cannot be displayed directly with []. The correct output method is: $pic[0]->title

Problem solved!

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

thinkphp prompts Cannot use ‘String’ as class name as it is in php7 environment reserved solution

The above is the detailed content of PHP Cannot use object of type stdClass as array in error solution. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:ThinkPHP data pagingNext article:ThinkPHP data paging