Solving an Array Reduce Interview Question - in PHP

Поделиться
HTML-код
  • Опубликовано: 24 ноя 2024

Комментарии • 23

  • @WesBos
    @WesBos Год назад +14

    Nice! Really cool to see it in PHP.

    • @MattStauffer
      @MattStauffer  Год назад

      Thanks so much for sharing your original video! It was such a great inspiration!

  • @opdavies
    @opdavies Год назад

    Great to see you back, Matt!

  • @sai_charan
    @sai_charan Год назад

    Thanks for sharing the native version!

  • @MarioPalomera
    @MarioPalomera Год назад +1

    Very nice! Thanks for sharing !

  • @aseemlalfakawma5084
    @aseemlalfakawma5084 Год назад

    Haven't seen you in a while, great video!

  • @nunomaduro
    @nunomaduro Год назад

    Really cool video, Matt!

  • @shawnveltman1482
    @shawnveltman1482 Год назад

    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. :)

  • @sampodlogar
    @sampodlogar Год назад

    Great video! I just noticed the typo in the description :)

  • @bartech101
    @bartech101 Год назад

    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

    • @bartech101
      @bartech101 Год назад +2

      And PHP native version is better.

  • @Necessarius
    @Necessarius Год назад

    0:20???

  • @zgetro
    @zgetro Год назад

    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.

  • @jezmck
    @jezmck Год назад +1

    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?

    • @MattStauffer
      @MattStauffer  Год назад +1

      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!!

  • @bremg9185
    @bremg9185 Год назад

    The non Laravel version is easier to read as per usual

  • @philbanks5075
    @philbanks5075 Год назад

    😢 Promo>SM!!