# Allow zero parameters in array_merge()?

- Thread: https://externals.io/message/105929
- Original archive: https://news-web.php.net/php.internals/105929
- Started by Benjamin Morel on 2019-06-14T17:15:07+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #105929 — Benjamin Morel — 2019-06-14T17:15:07+00:00

URL: https://externals.io/message/105929#105929

Hi Internals,

I'm wondering if there's any reason why `array_merge()` doesn't allow zero
arrays to be passed?

    `array_merge()`; // Warning:  `array_merge()` expects at least 1 parameter,
0 given

It would be reasonable IMO to return an empty array in this case. The
reason is, I'm often using it this way:

    $result = [];

    foreach (...) {
        $result[] = getSomeListOfItems();
    }

    if (! $result) {
        return [];
    }

    return array_merge(...$result);

If we allowed zero arrays to be passed, I could get rid of this repeated
empty array check before `array_merge()`.

Ben

---

## #105930 — Sara Golemon — 2019-06-14T17:21:37+00:00

URL: https://externals.io/message/105929#105930

On Fri, Jun 14, 2019 at 12:15 PM Benjamin Morel <benjamin.morel@gmail.com>
wrote:

> I'm wondering if there's any reason why `array_merge()` doesn't allow zero
> arrays to be passed?
>
>     `array_merge()`; // Warning:  `array_merge()` expects at least 1 parameter,
> 0 given
>
> It would be reasonable IMO to return an empty array in this case.
>

I don't see any issue with this plan. I say do it.

-Sara

---

## #105931 — G. P. B. — 2019-06-14T17:26:36+00:00

URL: https://externals.io/message/105929#105931

> On Fri, Jun 14, 2019 at 12:15 PM Benjamin Morel <benjamin.morel@gmail.com>
> wrote:
>
> > […]
> parameter,
> > […]
>
> I don't see any issue with this plan. I say do it.
>
> -Sara
>


Already the case in PHP 7.4
See changelog:
https://www.php.net/manual/en/function.array-merge.php#refsect1-function.array-merge-changelog

George P. Banyard

---

## #105932 — Benjamin Morel — 2019-06-14T17:40:08+00:00

URL: https://externals.io/message/105929#105932

>  Already the case in PHP 7.4

This, will teach me to scroll down the page. Thank you!

Ben
