array_is_list() Can Fool You
<?php
$data = [
'red',
'green',
'blue',
];
var_dump(array_is_list($data)); // true
unset($data[1]);
var_dump(array_is_list($data)); // false
$data[] = 'yellow';
var_dump(array_is_list($data)); // false
var_dump(array_keys($data)); // [0, 2, 3]
Here’s a special case that can save you from a surprising mistake: assuming that an array is a list just because it contains consecutive-looking values.
The nuance is that unset() does not reindex an array. Appending a new value uses the next integer key, but it doesn’t fill the gap.
The savior is array_values(). Or a reusage of the removed value.
See Also
- List, not list! [Try me]
PHP Features
Last updated: 09 November 2026