Re: RFC proposal - unpack iterator
| From: | Bartłomiej Krukowski | Date: | Wed, 12 Jul 2017 12:09:32 +0000 |
| Subject: | Re: RFC proposal - unpack iterator | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-99853@lists.php.net to get a copy of this message | ||
Hello,
Yes, this is exactly what I would like to achieve.
Best regards
2017-07-12 14:06 GMT+02:00 Marco Pivetta <ocramius@gmail.com>:
> On Wed, Jul 12, 2017 at 11:22 AM, Bartłomiej Krukowski <
> krukowski.bartlomiej@gmail.com> wrote:
>
>> Hello,
>> From PHP 5.6 we have possibility to add variadic functions and unpacking
>> arrays via *...*
>> Would be nice to extend responsibility of *...*. Sometimes in code I can
>> find lines similar to the following:
>>
>> $result = array_merge(['some value'], ['some other value'], $array);
>>
>>
>> I would like to shorten this line to the following:
>>
>> $result = ['some value', ['some other value'], ...$array];
>>
>>
>> And even allow to unpack more than one array:
>>
>> $result = ['some value', ['some other value'], ...$array,
>> ...$secondArray];
>>
>>
>> Using new operator we can produce shorter and more clearable code. I would
>> like to create RFC for my proposal. If you think idea can be useful,
>> please
>> give me an access for creating RFC.
>>
>> Best regards
>>
>
> Would this allow operations such as the following one?
>
> $a = [0];
> $b = [1];
> $otherArrays = [[2,3], [4,5]];
> $mergeAll = [...$a, ...$b, ...[...$otherArrays]]; // [0, 1, 2, 3, 4, 5]
>
> Marco Pivetta
>
> http://twitter.com/Ocramius
>
> http://ocramius.github.com/
>
>
>