Solving an Array Reduce Interview Question - in PHP

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

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

  • @WesBos
    @WesBos 2 года назад +14

    Nice! Really cool to see it in PHP.

    • @MattStauffer
      @MattStauffer  2 года назад

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

  • @opdavies
    @opdavies 2 года назад

    Great to see you back, Matt!

  • @nunomaduro
    @nunomaduro 2 года назад

    Really cool video, Matt!

  • @aseemlalfakawma5084
    @aseemlalfakawma5084 2 года назад

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

    • @MattStauffer
      @MattStauffer  2 года назад

      Thanks so much! Great to be back!

  • @MarioPalomera
    @MarioPalomera 2 года назад +1

    Very nice! Thanks for sharing !

  • @sai_charan
    @sai_charan 2 года назад

    Thanks for sharing the native version!

  • @jezmck
    @jezmck 2 года назад +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  2 года назад +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!!

  • @bartech101
    @bartech101 2 года назад

    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 года назад +2

      And PHP native version is better.

  • @sampodlogar
    @sampodlogar 2 года назад

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

  • @shawnveltman1482
    @shawnveltman1482 2 года назад

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

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

    0:20???

  • @zgetro
    @zgetro 2 года назад

    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.

  • @bremg9185
    @bremg9185 2 года назад

    The non Laravel version is easier to read as per usual

  • @philbanks5075
    @philbanks5075 2 года назад

    😢 Promo>SM!!