Re: [RFC][Under Discussion] Add functions array_key_first()and array_key_last()

From: Date: Wed, 04 Jul 2018 21:43:21 +0000
Subject: Re: [RFC][Under Discussion] Add functions array_key_first()and array_key_last()
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to internals+get-102588@lists.php.net to get a copy of this message
Am 28.06.2018 um 16:52 schrieb Levi Morrison:
I think there has been a lack of discussion about why this is desired. For me, it's always been implementing certain kinds of iterators that wrap arrays. This means that functions which return both the key and value are optimal for me. As I already outlined the functions which return the key-value pair are the most general and do result in clean code without drawbacks, at least for this use-case. Some people do not like this idea. One potential implication this that maybe their use-case is not the same as mine. What use-cases do other people have for this? Why are you wanting to grab the first or last value? What data structure or algorithm is this a bigger part of? Hi Levi,
sorry for the long-lasting answer. I use plain arrays relatively often when I develop caching mechanics for multiple rather complex entities. I query a set of suitable entites and store them as a plain array eg. in Redis. Each request now fetches this preprocessed entities. Sometimes all entities are required but I also have use cases where I filter/sort the list of entries and only one entity is interesting (in all cases I experienced either the first or the last element). This is my initial use case for this RFC. Are there other opinions about the necessity of this functions? Regards, Enno

« previous php.internals (#102588) next »