从列表中的每个对象中取出某个字段。
原型
wp_list_pluck( array $list, int|string $field, int|string $index_key = null )
描述
它具有与array_column()(PHP 5.5)相同的功能和原型,但也支持对象。
参数
$list
(array)
(Required)
对象或数组列表
$field
(int|string)
(Required)
从对象到场而不是整个对象的场
$index_key
(int|string)
(Optional)
来自对象的字段用作新数组的键。
返回值
(array)
找到的值的数组。如果
源文件
路径:wp-includes/functions.php
<?php
...
function wp_list_pluck( $list, $field, $index_key = null ) {
$util = new WP_List_Util( $list );
return $util->pluck( $field, $index_key );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/wp_list_pluck/