4 ms·
Array unpacking is going to help make a lot of coding situations more concise. There isn't a direct comparison in the article, but from what I understand, somet
by Minor49er 6y ago
Array unpacking is going to help make a lot of coding situations more concise. There isn't a direct comparison in the article, but from what I understand, something like this:
$array = array_merge(["a" => 0], $array1, $array2);
could be replaced with this:
$array = ["a" => 0, ...$array1, ...$array2];
It seems small here, but anything that stops devs from having to nest a bunch of array*() calls in PHP is an excellent change. I don't know how many times I've come across code that does something like this:
$array = array_values(array_unique(array_filter(array_merge($one, $two, $three))));
- reactspa 6y agoGood to have this in PHP. It's called "spread" in JavaScript.
- agumonkey 6y agoand a myriad of other names in schemes and ml dialects
- dragonwriter 6y ago...and Ruby and Python and...
- agumonkey 6y agoboth weren't in existence in the 80s
- pwdisswordfish6 6y agoAnd my axe.
- nkozyra 6y agoI always think of it as a variadic parameter, and I think spread has a little magic behind it.