DEV Community

Discussion on: Never use array_merge in a loop

Collapse
 
chemaclass profile image
Jose Maria Valera Reales

Well, you can use it for versions <7.4 as:

$merged = array_merge([], ...array_values($lists));
Enter fullscreen mode Exit fullscreen mode

Check it out: sandbox.onlinephpfunctions.com/cod...

And from 7.4, array_merge accept no arguments, therefore we can use it without the empty array as first arg:

$merged = array_merge(...array_values($lists));
Enter fullscreen mode Exit fullscreen mode