wpseek.com
A WordPress-centric search engine for devs and theme authors



array_is_list › WordPress Function

Since6.5.0
Deprecatedn/a
array_is_list ( $arr )
Parameters:
  • (array) $arr The array being evaluated.
    Required: Yes
See:
Returns:
  • (bool) True if array is a list, false otherwise.
Defined at:
Codex:

Polyfill for `array_is_list()` function added in PHP 8.1.

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.


Source

function 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;
	}
}