Reputation: 25
I have an array called $results, when I use function:
print_r($results);
I get the following.
Array
(
[0] => ProfileElement Object
(
[name] => John thomson
[email] => [email protected]
[Bio] => 20 years of engineering expertise
[url] => http://twitter.com
)
)
My goal is to echo [name] [email] [Bio] [url] values separately. But when I write the following code in php I don't get any values?
echo $results[0]["ProfileElement Objects"]["Bio"];
Does anyone know why? Isn't this an array inside an array?
Upvotes: 2
Views: 123
Reputation: 352
It is an object. You can get the 'Bio' value using:
echo $results[0]->Bio;
Upvotes: 1
Reputation: 4311
It's an object inside an array. It looks like you should be able to access it as $results[0]->name
, $results[0]->email
, etc.
Upvotes: 1
Reputation: 20475
Try doing:
$results[0]->name;
ProfileElement Object is the object type.
Upvotes: 1
Reputation: 174957
You were close.
echo $results[0]->bio;
Is probably what you want. $result[0]
is an object.
Also, depending on visibility, you may need to use a getter method.
Upvotes: 5
Reputation: 48897
It appears that the array element contains an object, not another array. To access the object property, use the ->
operator:
echo $results[0]->Bio;
Upvotes: 9