so I have this array saved in a variable title $arr. I want to grab or echo the value of [slug]

Array ( [0] => stdClass Object ( [term_id] => 11 
                                 [name] => Community Service 
                                 [slug] => community-service 
                                 [term_group] => 0 
                                 [term_taxonomy_id] => 11 
                                 [taxonomy] => category

So i want something like this

echo $arr[slug]

which would then display "community-service". I am sure this is something pretty easy but i can't figure out how to grab the value out of an array stdClass and echo it on the page. Thank you.

share|improve this question
Did that data come from a call to json_decode()? – Jack May 21 '12 at 16:16

1 Answer

up vote 4 down vote accepted

The array $arr contains 1 item which is an object. You have to use the -> syntax to access it's attributes.

echo $arr[0]->slug;

share|improve this answer
Simple...thank you so much. – user982853 May 21 '12 at 16:27

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.