Re: Two new functions array_first() and array_last()
| From: | Levi Morrison via internals | Date: | Wed, 18 Oct 2023 15:47:02 +0000 |
| Subject: | Re: Two new functions array_first() and array_last() | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-121402@lists.php.net to get a copy of this message | ||
> > This is simply not true, 0 is not always the first key in a list,
> > especially after filtering it. Hence there is a need for this function
> > in the first place.
>
> Just to clarify this point: If 0 is not the first key, then it's not a list.
> After filtering a list, you get an array that may or may not be a list:
> https://3v4l.org/VegUr
I don't see how
array_is_list is relevant to array_first and
array_last. PHP arrays are ordered:
$foo = [
"first" => 1,
"third" => 3,
];
It would be perfectly fine to use array_first or array_last with
$foo. I think probably you would use array_key_first and
array_key_last so you also get the key and not just the value, but I
don't see any need to reduce array_first and array_last to only be
logical or correct with arrays that uphold array_is_list.