array_is_list( array $arr )

Polyfill for array_is_list() function added in PHP 8.1.


Description

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.

See also


Parameters

$arr

(Required) The array being evaluated.


Return

(bool) True if array is a list, false otherwise.


Source

File: wp-includes/compat.php

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

Changelog

Changelog
Version Description
6.5.0 Introduced.