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);
Shakti singh
source share