我有一个数组,我想要过滤掉某些键。假设$subcats等于这个数组:
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
)
)我想要的只是term_ids在它自己的数组中。
我已经尝试过foreach和array_values,但我现在似乎还不能完全理解它。我应该使用array_filter吗?
所以结果应该是$term_ids = array( 4, 5 );
发布于 2011-10-05 12:07:54
$termIds = array_map(function($i) { return $i->term_id; }, $subcats);此语法需要PHP 5.3+。
https://stackoverflow.com/questions/7656614
复制相似问题