What Array Is A List¶
array_is_list() was introduced in PHP 8.1, and tells if an array is a list: an array is considered a list if its keys consist of consecutive numbers from 0 to count($array)-1.
There are some edge cases: first, array_is_list() is sensible to insert order: give the right indices in the wrong order, say 1 is inserted before 0, and the resulting array is not a list.
You can then turn that array into an actual list by using ksort(), asort() or sort(), which checks the keys while sorting the array.
Finally, the best way to make the array a list is array_values().
See Also¶
array_is_list() and sorting [Try me]