On 10/30/2016 11:59 PM, Yasuo Ohgaki wrote: > There should be delete option. It's more useful if there is this option. > > mixed array_first(array $arr [,bool $get_key = FALSE [, bool > $remove_entry=FALSE]]); > mixed array_last(array $arr [,bool $get_key = FALSE [, bool > $remove_entry=FALSE]]); > > Problem with this is error condition. When array is empty, what should > be returned from these with default option? Returning NULL for empty > array would be enough. IMO. > > On Mon, Oct 31, 2016 at 1:52 AM, Levi Morrison <le...@php.net> wrote: >> To clarify, do you use the return value of these functions or rely on >> the IAP moving to also get the key? > > Depends on code, but I usually use them just to get value of head/tail > element. It could be array_slice/splice, so I don't have much problem > with removing internal array position pointer. However, I still need > current() or each() to get value from returned array. This applies to > array_first/last($arr, TRUE); > > Regards, > > -- > Yasuo Ohgaki > yohg...@ohgaki.net >
Flags are usually a bad design decision, it's better to make it fully explicit and provide dedicated APIs for everything. This is much easier for the reader and reading is more important than anything else. ``` /** Get the first element in the array. */ function array_first(array $array); /** Get the key of the first element in the array. */ function array_first_key(array $array); /** Get the last element in the array. */ function array_last(array $array); /** Get the key of the last element in the array. */ function array_last_key(array $array); /** Get and remove the first element from the array. */ function array_take_first(array $array); /** Get the key of the first element in the array and remove it. */ function array_take_first_key(array $array); /** Get and remove the last element from the array. */ function array_take_last(array $array); /** Get the key of the last element in the array and remove it. */ function array_take_last_key(array $array); ``` Returning `null` is imho the most sensible thing we can do if the array is empty. -- Richard "Fleshgrinder" Fussenegger -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php