DEV Community

Discussion on: How to Append Arrays in PHP: + vs. array_merge

bdelespierre profile image
Benjamin Delespierre

have you tried this?

[1,2,3,...[4,5]] == range(1,5)
Enter fullscreen mode Exit fullscreen mode
davidrjenni profile image
David Author

Thanks for your feedback. 🙏 You are absolutely right. The spread operator is a more readable alternative for array_merge, if you are working with array literals.

⚠️ In all current PHP versions (up to 8.0) the spread operator does not work for arrays with string keys.

But that will change in PHP 8.1 . 🎉🎉🎉

Then it's effectively an array_merge alternative for array literals.