Automattic\WooCommerce\Internal\Utilities
ArrayUtil::array_is_list
Determines if the given array is a list.
An array is considered a list if its keys consist of consecutive numbers from 0 to count($array)-1.
Polyfill for array_is_list() in PHP 8.1.
Метод класса: ArrayUtil{}
Хуков нет.
Возвращает
true|false. True if array is a list, false otherwise.
Использование
$result = ArrayUtil::array_is_list( $arr ): bool;
- $arr(массив) (обязательный)
- The array being evaluated.
Код ArrayUtil::array_is_list() ArrayUtil::array is list WC 10.4.3
public static function array_is_list( array $arr ): bool {
if ( function_exists( 'array_is_list' ) ) {
return array_is_list( $arr );
}
if ( ( array() === $arr ) || ( array_values( $arr ) === $arr ) ) {
return true;
}
$next_key = -1;
foreach ( $arr as $k => $v ) {
if ( ++$next_key !== $k ) {
return false;
}
}
return true;
}