Re: Two new functions array_first() and array_last()

From: Date: Wed, 18 Oct 2023 15:52:55 +0000
Subject: Re: Two new functions array_first() and array_last()
References: 1 2 3 4 5 6 7 8 9 10 11  Groups: php.internals 
Request: Send a blank email to internals+get-121403@lists.php.net to get a copy of this message
On Wed, 18 Oct 2023 at 17:47, Levi Morrison <levi.morrison@datadoghq.com> wrote: > > 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. > I didn't mean that array_first/last should only work on lists; they should work on any array as you mentioned. I was just correcting a statement about lists. Sorry if I wasn't clear. - Benjamin

« previous php.internals (#121403) next »