wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



wp_list_pluck › WordPress Function

Seit3.1.0
Veraltetn/v
wp_list_pluck ( $input_list, $field, $index_key = null )
Parameter: (3)
  • (array) $input_list List of objects or arrays.
    Erforderlich: Ja
  • (int|string) $field Field from the object to place instead of the entire object.
    Erforderlich: Ja
  • (int|string) $index_key Optional. Field from the object to use as keys for the new array. Default null.
    Erforderlich: Nein
    Standard: null
Gibt zurück:
  • (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 `$input_list` will be preserved in the results.
Definiert in:
Codex:
Changelog:
  • 4.0.0
  • 4.7.0

Plucks a certain field out of each object or array in an array.

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


Quellcode

function wp_list_pluck( $input_list, $field, $index_key = null ) {
	if ( ! is_array( $input_list ) ) {
		return array();
	}

	$util = new WP_List_Util( $input_list );

	return $util->pluck( $field, $index_key );
}