Re: Calling array_merge / array_merge_recursive without arguments
| From: | Christoph M. Becker | Date: | Tue, 21 May 2019 11:40:25 +0000 |
| Subject: | Re: Calling array_merge / array_merge_recursive without arguments | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-105773@lists.php.net to get a copy of this message | ||
On 21.05.2019 at 12:54, G. P. B. wrote:
> On Tue, 21 May 2019 at 10:29, Nikita Popov <nikita.ppv@gmail.com> wrote:
>
>> On Sat, May 18, 2019 at 9:37 PM Dik Takken <d.takken@xs4all.nl> wrote:
>>
>>> Good point. I did a quick scan of the source code and came up with a
>>> list of possible candidates for a similar treatment:
>>>
>>> array_map()
>>
>> This one makes sense in theory, because array_map(null, ...$arrays) is a
>> way to perform a zip operation in PHP. Unfortunately there is an ugly
>> special case if there is only a single array, which makes this not actually
>> usable in practice, unless you know that there are at least two arrays. As
>> such, accepting zero arrays wouldn't be very useful unless we also want to
>> fix that issue (PHP 8 maybe?)
>
> I'm not sure I totally understand the edge case, moreover this isn't
> currently documented.
> Mind sharing an example or explaining a bit more in detail such that I can
> update the documentation?
If you pass only a single array to array_map(NULL, …), you don't get an
array of arrays, but a single flat array, see <https://3v4l.org/sqtqS>.
--
Christoph M. Becker