[PHP 8 >= 8.1.0]
array_is_list — Checks whether a given array
is a list
Description
array_is_list[array $array
]: bool
Parameters
array
The array being evaluated.
Return Values
Returns true
if array
is a list, false
otherwise.
Examples
Example #1 array_is_list[] example
Notes
Note:
This function returns
true
on empty arrays.
phpnet at jesseschalken dot com ¶
8 months ago
Polyfills that call `array_keys[]`, `array_values[]` or `range[]` are inefficient because they create new arrays unnecessarily.
Please use this polyfill instead which creates no new arrays and only does a single pass over the given array.
divinity76+spam at gmail dot com ¶
4 months ago
slightly optimized version of phpnet at jesseschalken dot com's excellent array_is_list:
benchmarks: //3v4l.org/9BPqL
why is this faster you ask? because post-increment does more,
here is what pre-increment actually means:
step 1: increment the value by 1.
step 2: return the value.
here is what post-increment actually means:
step 1: create a copy of the original value.
step 2: increment the original value by 1.
step 3: return the copy.
another question might be "why didn't you write `if [$k !== ++$i] {` ? ... that is a good question! turns out that ++$i;if[$k!==$i]{...} is faster on PHP7 than if[$k !== ++$i]{...} for reasons unknown to me.. [if you have an answer, feel free to email me about it!]
[i have NOT checked if PHP8/jit auto-optimize this stuff, but at least back in PHP7 it's true that pre-increment is faster than post-increment, and this polyfill is primarily for PHP7]
Matteo Galletti ¶
10 months ago
Polyfill implementation for PHP versions lower than 8.1.
info at ensostudio dot ru ¶
10 months ago
old school polyfill [:
iradu at unix-world dot org ¶
7 months ago
// How about: