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

From: Date: Tue, 17 Oct 2023 09:34:37 +0000
Subject: Re: Two new functions array_first() and array_last()
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-121345@lists.php.net to get a copy of this message
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

« previous php.internals (#121345) next »