On Sat, Sep 13, 2025 at 1:24 PM Rowan Tommins [IMSoP] <[email protected]>
wrote:

> On 12 September 2025 20:02:04 BST, "Dušan Kreheľ" <[email protected]>
> wrote:
> >[+] array_push
> >[-] array_pop
> >[-<] array_shift
> >
> >array_unshift() is a special case of array_merge(), so it would then need
> >syntactic sugar for merging arrays, or rather a reserved merge.
>
> array_unshift is no more a special case of array_merge than array_push,
> particularly in the single-element case we're talking about here - it's
> really just the same operation at the other end of the array.
>
> Since we have an extremely well-established array_push shorthand, so don't
> need a new one, we could perhaps have "<" for "at start", and "-" for "pop":
>
> $foo[] = $toPush;
> $popped = $foo[-];
> $foo[<] = $toUnshift;
> $shifted = $foo[-<];
>
> I'm not totally convinced it's necessary, but I don't completely hate it.
>


 I think `$item = $list[-]` makes sense instead of writing `$item
= array_pop($list)`.

I don't think we should add shorthand operations for `array_unshift()` and
`array_shift()`, as those are slower operations on array, O(n), compared to
`array_push()` and `array_pop()` that are O(1).
I mean, we should not make it easier to use, a function is good enough.

-- 
Alex

Reply via email to