Re: Feature request - allow to append multiple elements to an array
| From: | Iván Arias | Date: | Sun, 29 Mar 2020 09:08:07 +0000 |
| Subject: | Re: Feature request - allow to append multiple elements to an array | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-109410@lists.php.net to get a copy of this message | ||
Hi all,
I think David's syntax make more sense. Maybe we could support multiple arguments for push
operator, just like array_push does:
$arr[] = 1, 2, 3; // push these 3 values
$arr[] = 1, 2, ... [3, 4, 5], 6; // push these 6 values
Regards,
Iván Arias.
Obtener Outlook para Android<https://aka.ms/ghei36>
________________________________
From: David Rodrigues <david.proweb@gmail.com>
Sent: Sunday, March 29, 2020 5:32:32 AM
To: Michael Voříšek - ČVUT FEL <vorismi3@fel.cvut.cz>
Cc: PHP Internals <internals@lists.php.net>
Subject: Re: [PHP-DEV] Feature request - allow to append multiple elements to an array
I think it useful, despite that it could be done by using array_push() as
Woortmann said. Anyway, I think valid a new proposal for thinks like that.
But I will suggests this:
$arr[] = ... $items;
Atenciosamente,
David Rodrigues
Em sáb., 28 de mar. de 2020 às 20:07, Michael Voříšek - ČVUT FEL <
vorismi3@fel.cvut.cz> escreveu:
> Hi all PHP gurus!
>
> This is a feature request / RFC for the following use-case:
>
> $res = [];
> foreach ($arr as $i) {
> foreach (make_res($i) as $v) {
> $res[] = $v;
> }
> }
>
> Array_merge in loop is very sloop so it is not a solution.
>
> which I propose to shorten to:
>
> $res = [];
> foreach ($arr as $i) {
> $res[...] = make_res($i);
> }
>
> Appending multiple elements to an array is very common use-case.
>
> With kind regards / Mit freundlichen Grüßen / S přátelským pozdravem,
>
> Michael Voříšek