Unpacking inside arrays using spread operator in PHP

1 · Amit Merchant · May 12, 2020, midnight
If you’ve ever worked with JavaScript, you might be well aware of this feature. So basically, from PHP 7.4, you would be able to unpack arrays into another array using spread operator [...]. Pre PHP 7.4, if you want to merge two arrays, you would need to use methods like array_merge. Take this for example. <?php // Pre PHP 7.4 $array = ['foo', 'bar']; $result = array_merge($array, ['baz']); print_r($result); // Array([0] => baz [1] => foo [2] => bar) But from PHP 7.4, you can achieve above u...