4 ms·
What `array_is_list()` changes is that it makes this check fast. Previously, the fastest method of checking for a list-like array was `$arr == array_values($arr
by duskwuff 6y ago
What `array_is_list()` changes is that it makes this check fast. Previously, the fastest method of checking for a list-like array was `$arr == array_values($arr)`, which was slow on large lists and could fail entirely on some unusual structures containing circular references.
(I was involved in the development of this function: https://github.com/php/php-src/pull/4886 https://github.com/php/php-src/pull/4886)
- tyingq 6y agoIs array_is_map(), etc, planned? Or is the pure php equivalent fast enough for those?
- duskwuff 6y agoYou mean `!array_is_list()`? As far as PHP is concerned, a list is a subset of arrays where the keys are ordered integers starting at zero. Any array that doesn't fit this pattern could be considered a "map" -- there's no middle ground.