Reputation:
I have this array called $locations
and this is what it produces if I use print_r
:
Array
(
[0] => stdClass Object
(
[term_id] => 40
[name] => California
[slug] => california
[term_group] => 0
[term_taxonomy_id] => 41
[taxonomy] => location
[description] =>
[parent] => 0
[count] => 6
)
)
What I need to get from this array is California
only, but I can't figure out what variable produces that. I tried $locations->name
and $locations[name]
but none of those work.
Upvotes: 0
Views: 60
Reputation: 870
$locations seems to be an array (with 1 value, that is an object), so:
$locations[0]->name
Upvotes: 3
Reputation: 152216
Just try with:
$data = array( /* your data */ );
foreach ($data as $obj) {
$name = $obj->name; // California - and others in the nest steps
// if array contains more elements
}
Upvotes: 0