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?

Pennywise83
  • 1,784
  • 5
  • 31
  • 44
  • Related: [Able to see a variable in print_r()'s output, but not sure how to access it in code](http://stackoverflow.com/questions/6322084/able-to-see-a-variable-in-print-rs-output-but-not-sure-how-to-access-it-in-c) – hakre Aug 28 '12 at 14:22

1 Answers1

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.

Jeroen
  • 13,056
  • 4
  • 42
  • 63