0

I have an array like this:

Array
(
    [count] => 2
    [0] => stdClass Object
        (
            [term_id] => 3109
            [name] => Aliens: Colonial Marines
            [slug] => aliens-colonial-marines
        )

    [1] => stdClass Object
        (
            [term_id] => 228
            [name] => Dragon Quest X: Rise of the Five Tribes
            [slug] => dragon-quest-x-rise-of-the-five-tribes
        )

)

I need to run a cycle that grab the "slug" value from each element. How I can accomplish this result?

1

1 Answer 1

3
foreach ($array as $key => $value) {
    if (is_object ($value)) echo $value->slug;
}

It simply loops through the array $array and if the element is an object (so it doesn't try to parse count), it echoes slug.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.