Reputation: 749
I am trying to get the first "url" from what I think is an array.
This get the "url" works fine but it not usable obviously
print_r ($wantedimage[0]);
But this gets error:
Catchable fatal error: Object of class stdClass could not be converted to string.
When I try
echo $wantedimage[0];
What am I doing wrong please?
Upvotes: 0
Views: 1540
Reputation: 639
Use var_dump
or Kint.
And also $wantedimage[0]
, what's the type of this? Integer, Float, String, Array, ..., What?
Upvotes: 2
Reputation: 749
Worked it out with help from the answers here and my own tenacity.
This worked for some reason. So please do not delete question as I flagged for if it is useful.
$wantedimage =$data-> images;
$a0=$wantedimage[0]->url;
echo $a0;
Thanks for the help.
Sorry I was so stressed about it. It's part of a bigger code with many nested levels.
Upvotes: 0
Reputation: 4152
You should use something like this:
foreach($wantedimage as $key => $value)
{
echo $value;
}
Or based on it's structure:
$wantedimage[0]->url
Upvotes: 4