ArrayUtil::get_value_or_default()public staticWC 1.0

Gets the value for a given key from an array, or a default value if the key doesn't exist in the array.

This is equivalent to "$array[$key] ?? $default" except in one case: when they key exists, has a null value, and a non-null default is supplied:

$array = ['key' => null] $array['key'] ?? 'default' => 'default' ArrayUtil::get_value_or_default($array, 'key', 'default') => null

Метод класса: ArrayUtil{}

Хуков нет.


Разное|null. The value for the key, or the default value passed.


$result = ArrayUtil::get_value_or_default( $array, $key, $default );
$array(массив) (обязательный)
The array to get the value from.
$key(строка) (обязательный)
The key to use to retrieve the value.
The default value to return if the key doesn't exist in the array.
По умолчанию: null

Код ArrayUtil::get_value_or_default() WC 8.3.1

public static function get_value_or_default( array $array, string $key, $default = null ) {
	return array_key_exists( $key, $array ) ? $array[ $key ] : $default;