开发者

reducing/filtering an array

I have an array which I want to filter out certain keys. Let's say $subcats equals this array:

Array
(
    [0] => stdClass Object
        (
            [term_id开发者_开发问答] => 4
            [term_group] => 0
            [term_taxonomy_id] => 4
            [taxonomy] => category
        )

    [1] => stdClass Object
        (
            [term_id] => 5
            [term_group] => 0
            [term_taxonomy_id] => 5
            [taxonomy] => category
        )

)

All I want is the term_ids in it's own array.

I've tried foreach and array_values, but I can't seem to wrap my head around it at the moment. Should I be using array_filter?

So the result should be $term_ids = array( 4, 5 );


$termIds = array_map(function($i) { return $i->term_id; }, $subcats);

This syntax requires PHP 5.3+.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜