Checking if array keys are out of order using array_is_list() in PHP 8.1

1 · Amit Merchant · July 8, 2021, 6:21 a.m.
Working with arrays, there might come a time when you want to check if the array in question is a list or not. So, how does an array qualifies as a “list”? An array can be called a list when the keys (must be in form of an integer) are consecutive in nature. Meaning, if the array is an associative array with integer keys, it shouldn’t have missing array offsets, or contains out-of-order keys. The array_is_list() function Caveat For instance, take the following for example. $cars = [ 0 => '...