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

From: Date: Tue, 17 Oct 2023 09:37:20 +0000
Subject: Re: Two new functions array_first() and array_last()
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-121346@lists.php.net to get a copy of this message
On Tue, Oct 17, 2023 at 11:34 AM Aleksander Machniak <alec@alec.pl> wrote: > > On 17.10.2023 11:29, Robert Landers wrote: > > $value = array_value_first($array, $key); > > if($key === null) // handle error > > else // do something with $value > > > > You can also freely ignore the key, if you don't need it or care about > > error checking. That would save doing two function calls on the same > > array, just to do some error checking. > > > > Please, no. What's wrong with count() or empty()? > > +1 for array_first() and array_last(). The only problem is probably a > big BC break. I myself have array_first() defined in my framework. > > -- > Aleksander Machniak > Kolab Groupware Developer [https://kolab.org] > Roundcube Webmail Developer [https://roundcube.net] > ---------------------------------------------------- > PGP: 19359DC1 # Blog: https://kolabian.wordpress.com > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > Hey Aleksander, > Please, no. What's wrong with count() or empty()? Nothing. Why not either one? You don't have to use the $key variable and you can use count() or empty(), but for me personally, it makes a lot of sense.

« previous php.internals (#121346) next »