CKTIS / PHP
array_is_list()
Test whether the keys, in iteration order, are consecutive integers starting at zero.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
array_is_list(array $array): boolTest whether the keys, in iteration order, are consecutive integers starting at zero. The empty array is a list. A gap or a different insertion order makes the result false even when all keys are integers. This check helps distinguish a sequence from a keyed record before serialization.
Signature
array_is_list(array $array): bool
Example output
[true,false,true]
Examples
<?php
echo json_encode([array_is_list([]), array_is_list([1=>'B',0=>'A']), array_is_list(['A','B'])]);
Result
[true,false,true]