wpseek.com
Uma área de pesquisa sobre o WordPress para devs e autores do tema



array_is_list › WordPress Function

Desde6.5.0
Obsoleton/a
array_is_list ( $arr )
Parâmetros:
  • (array) $arr The array being evaluated.
    Required: Yes
Ver:
Retorna:
  • (bool) True if array is a list, false otherwise.
Definido em:
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.


Fonte

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