0

我有一个这样的数组:

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
        )

)

我需要运行一个从每个元素中获取“slug”值的循环。我怎样才能完成这个结果?

4

1 回答 1

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

它只是循环遍历数组$array,如果元素是一个对象(所以它不会尝试解析count),它会回显slug

于 2012-05-23T18:20:34.507 回答