PHP error Cannot use object of type stdClass as array in error solution_PHP tutorial

WBOY
Release: 2016-07-13 10:28:29
Original
1124 people have browsed it

Many people get "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 a two-dimensional array like this:

Copy code The code is as follows:
Array (
[0] => stdClass Object (
[id] = > 1
[title] => Recruitment Information
[size] => 300*150
[pic] => ./upload/20140602093535.jpg
[state] => ; 0 )
[1] => stdClass Object (
[id] => > [pic] => ./upload/20140602093443.jpg
[state] => 0 )
)


The method to start writing the output is: $pic[0][title]
The above error appears as a result.

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

Problem solved!

http://www.bkjia.com/PHPjc/788613.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/788613.htmlTechArticleMany people get "Fatal error: Cannot use object of type stdClass as array" when PHP outputs a two-dimensional array. in…”. The solution is analyzed as follows: There is such a two-dimensional number...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!