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.
Method of the class: ArrayUtil{}
No Hooks.
Return
true|false
. True if array is a list, false otherwise.
Usage
$result = ArrayUtil::array_is_list( $arr ): bool;
- $arr(array) (required)
- The array being evaluated.
ArrayUtil::array_is_list() ArrayUtil::array is list code WC 9.6.0
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; }