Allow zero parameters in array_merge()?
| From: | Benjamin Morel | Date: | Fri, 14 Jun 2019 17:15:07 +0000 |
| Subject: | Allow zero parameters in array_merge()? | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-105929@lists.php.net to get a copy of this message | ||
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