Re: Regarding array_shift()/array_unshift()

From: Date: Wed, 02 Jun 2021 08:25:36 +0000
Subject: Re: Regarding array_shift()/array_unshift()
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-114691@lists.php.net to get a copy of this message
On 02/06/2021 00:34, Mike Schinkel wrote:
But from all this I do agree with you that just returning an array would likely be acceptable. ----- This would not be a great solution for really large arrays, but then we can't eliminate the need for a developer to have a reasonable level of knowledge, right? So: $unshifted = $array->unshift($new_element); $shifted = $array->shift(); But, we could also possibly use better names for these: $right_shifted = $array->shift_right(...$new_element(s)); $left_shifted = $array->shift_left([element_count]);
IMO for unshift() it'd be fine to return a new array, but when processing a list of things in a FIFO pattern I often used array_shift() to get the first "job" out of the array. If $array->shift() returns a new array then how do I access the first item? I mean sure one can call reset first to get it, but I find this isn't great ergonomics compared to the existing. Best, Jordi -- Jordi Boggiano @seldaek - https://seld.be

« previous php.internals (#114691) next »