wpseek.com
WordPress开发者和主题制作者的搜索引擎



array_is_list › WordPress Function

Since6.5.0
已弃用n/a
array_is_list ( $arr )
参数:
  • (array) $arr The array being evaluated.
    Required: Yes
查看:
返回:
  • (bool) True if array is a list, false otherwise.
定义在:
文档:

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.


源码

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