Automattic\WooCommerce\Utilities
ArrayUtil::select_as_assoc
Returns a new assoc array with format [ $key1 => $item1, $key2 => $item2, ... ] where $key is the value of the selector and items are original items passed.
Метод класса: ArrayUtil{}
Хуков нет.
Возвращает
Массив
. The converted assoc array.
Использование
$result = ArrayUtil::select_as_assoc( $items, $selector_name, $selector_type ): array;
- $items(массив) (обязательный)
- Items to use for conversion.
- $selector_name(строка) (обязательный)
- Key, method or property name to use as a selector.
- $selector_type(int)
- Selector type, one of the SELECT_BY_ constants.
По умолчанию: self::SELECT_BY_AUTO*
Код ArrayUtil::select_as_assoc() ArrayUtil::select as assoc WC 9.9.5
public static function select_as_assoc( array $items, string $selector_name, int $selector_type = self::SELECT_BY_AUTO ): array { $selector_callback = self::get_selector_callback( $selector_name, $selector_type ); $result = array(); foreach ( $items as $item ) { $key = $selector_callback( $item ); self::ensure_key_is_array( $result, $key ); $result[ $key ][] = $item; } return $result; }