You cannot use an object of type stdClass as array (php)

Possible duplicate:
Fatal error: you cannot use an object of type stdClass as array in

Please continue to get this error: Fatal error: you cannot use an object of type stdClass as an array in C: \ XAMMP \ xampp \ htdocs \ Yemi \ geograph \ table.php on line 31

This is the php I'm trying to run:

php code

+8
json php
source share
1 answer

In fact, you are trying to access an object as an array.

I can guess that you have a problem when you use json_decode , which returns an object and inside the foreach that you are trying to get to it, as an associative array.

Passing the second argument as true to json_decode causes it to return an associative array.

Make the following change.

Change this line of code

 $items = json_decode($contents); 

For

 $items = json_decode($contents, true); 
+31
source share

All Articles