WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WP_List_Util::pluck() public WP 4.7.0

Plucks a certain field out of each object in the list.

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

{} Это метод класса: WP_List_Util{}

Хуков нет.

Возвращает

Массив. 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.

Использование

$WP_List_Util = new WP_List_Util();
$WP_List_Util->pluck( $field, $index_key );
$field(число/строка) (обязательный)
Field from the object to place instead of the entire object
$index_key(число/строка)
Field from the object to use as keys for the new array.
По умолчанию: null

Список изменений

С версии 4.7.0 Введена.

Код WP_List_Util::pluck() WP 5.5.3

<?php
public function pluck( $field, $index_key = null ) {
	$newlist = array();

	if ( ! $index_key ) {
		/*
		 * This is simple. Could at some point wrap array_column()
		 * if we knew we had an array of arrays.
		 */
		foreach ( $this->output as $key => $value ) {
			if ( is_object( $value ) ) {
				$newlist[ $key ] = $value->$field;
			} else {
				$newlist[ $key ] = $value[ $field ];
			}
		}

		$this->output = $newlist;

		return $this->output;
	}

	/*
	 * When index_key is not set for a particular item, push the value
	 * to the end of the stack. This is how array_column() behaves.
	 */
	foreach ( $this->output as $value ) {
		if ( is_object( $value ) ) {
			if ( isset( $value->$index_key ) ) {
				$newlist[ $value->$index_key ] = $value->$field;
			} else {
				$newlist[] = $value->$field;
			}
		} else {
			if ( isset( $value[ $index_key ] ) ) {
				$newlist[ $value[ $index_key ] ] = $value[ $field ];
			} else {
				$newlist[] = $value[ $field ];
			}
		}
	}

	$this->output = $newlist;

	return $this->output;
}