On Tue, Oct 17, 2023 at 11:34 AM Aleksander Machniak <a...@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. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php