It's a couple of years since I've used PHP, but can't you simply do `$carry[$name][$key] += $val` (i.e. without initialising it) relying on it adding $val to nothing or maybe `$carry[$name][$key] = ($carry[$name][$key] ?: 0) + $val` to be a little safer?
Your second one definitely works! With the first one, if you try to do += on an undefined key, you'll get an error, so that wouldn't work. Thanks for sharing!!
First before making code look more elegant I'll use $name = isset( $item['name'] ) ? $item['name'] : null; if ( is_null( $name ) ) continue; or do something else, but assuming 'name' index is always present is ask for a NOTICE
Love the video, thanks Matt! I tend to like using $carry[$name] ??= [] & $carry[$name][$key] ??= 0 just to clean things up, but obviously that's a personal preference. :)
Hi @Matt Cool explanation after edit video, suggesttion by Titan. it could put more value to video if you add Big (O) value of your function. or in simple word it's space 🚀 and time ⌛ complexity.
Nice! Really cool to see it in PHP.
Thanks so much for sharing your original video! It was such a great inspiration!
Great to see you back, Matt!
Thank you so much!!
Really cool video, Matt!
Thank you my friend!
Haven't seen you in a while, great video!
Thanks so much! Great to be back!
Very nice! Thanks for sharing !
Thanks Mario!
Thanks for sharing the native version!
My pleasure!
It's a couple of years since I've used PHP, but can't you simply do `$carry[$name][$key] += $val` (i.e. without initialising it) relying on it adding $val to nothing or maybe `$carry[$name][$key] = ($carry[$name][$key] ?: 0) + $val` to be a little safer?
Your second one definitely works! With the first one, if you try to do += on an undefined key, you'll get an error, so that wouldn't work.
Thanks for sharing!!
First before making code look more elegant I'll use $name = isset( $item['name'] ) ? $item['name'] : null; if ( is_null( $name ) ) continue; or do something else, but assuming 'name' index is always present is ask for a NOTICE
And PHP native version is better.
Great video! I just noticed the typo in the description :)
HA! Nice catch. Thanks!
Love the video, thanks Matt! I tend to like using $carry[$name] ??= [] & $carry[$name][$key] ??= 0 just to clean things up, but obviously that's a personal preference. :)
0:20???
Hi @Matt
Cool explanation after edit video, suggesttion by Titan.
it could put more value to video if you add Big (O) value of your function. or in simple word it's space 🚀 and time ⌛ complexity.
The non Laravel version is easier to read as per usual
😢 Promo>SM!!