Open utterances-bot opened 1 year ago
There's a third way to merge arrays, using the spread operator.
$first = [1, 2, 3];
$second = [3, 4, 5];
$merged = [...$first, ...$second];
var_dump($merged);
/*
array(7) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
int(3)
[4]=>
int(4)
[5]=>
int(5)
}
*/
Two ways to merge arrays in PHP — Amit Merchant — A blog on PHP, JavaScript, and more
If you’re a seasoned PHP developer, you must have come across the need to merge two or more arrays in PHP. And the bona fide way to do this is by using the array_merge() function.
https://www.amitmerchant.com/two-ways-to-merge-arrays-in-php/