wp_list_pluck( array $list, int|string $field, int|string $index_key = null )

Pluck a certain field out of each object in a list.


Description

This has the same functionality and prototype of array_column() (PHP 5.5) but also supports objects.


Parameters

$list

(Required) List of objects or arrays

$field

(Required) Field from the object to place instead of the entire object

$index_key

(Optional) Field from the object to use as keys for the new array.

Default value: null


Return

(array) Array of found values. If $index_key is set, an array of found values with keys corresponding to $index_key. If $index_key is null, array keys from the original $list will be preserved in the results.


Source

File: wp-includes/functions.php

function wp_list_pluck( $list, $field, $index_key = null ) {
	$util = new WP_List_Util( $list );
	return $util->pluck( $field, $index_key );
}


Changelog

Changelog
Version Description
WP-4.7.0 Uses WP_List_Util class.
WP-4.0.0 $index_key parameter added.
WP-3.1.0 Introduced.