note 126794 added to function.array-is-list
| From: | phpnet at jesseschalken dot com | Date: | Sat, 22 Jan 2022 12:47:53 +0000 |
| Subject: | note 126794 added to function.array-is-list | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-217535@lists.php.net to get a copy of this message | ||
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.
<?php
if (!function_exists("array_is_list")) {
function array_is_list(array $array): bool
{
$i = 0;
foreach ($array as $k => $v) {
if ($k !== $i++) {
return false;
}
}
return true;
}
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.135 (proxied: 2405:6e00:2f77:2101:c9d0:58a1:e705:bc40)
----
Manual Page -- https://php.net/manual/en/function.array-is-list.php
Edit -- https://main.php.net/note/edit/126794
Del: integrated -- https://main.php.net/note/delete/126794/integrated
Del: useless -- https://main.php.net/note/delete/126794/useless
Del: bad code -- https://main.php.net/note/delete/126794/bad+code
Del: spam -- https://main.php.net/note/delete/126794/spam
Del: non-english -- https://main.php.net/note/delete/126794/non-english
Del: in docs -- https://main.php.net/note/delete/126794/in+docs
Del: other reasons-- https://main.php.net/note/delete/126794
Reject -- https://main.php.net/note/reject/126794
Search -- https://main.php.net/manage/user-notes.php