Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Cyborg)
  • No Skin
Collapse
Brand Logo

CIRCLE WITH A DOT

  1. Home
  2. Uncategorized
  3. #PHP is truly the gift that keeps on giving: https://3v4l.org/aapUB```php$a = ["min", "max", "crazy", "shit"];var_dump(min($a));```=> `string(5) "crazy"`

#PHP is truly the gift that keeps on giving: https://3v4l.org/aapUB```php$a = ["min", "max", "crazy", "shit"];var_dump(min($a));```=> `string(5) "crazy"`

Scheduled Pinned Locked Moved Uncategorized
php
7 Posts 6 Posters 11 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • girgias@phpc.socialG This user is from outside of this forum
    girgias@phpc.socialG This user is from outside of this forum
    girgias@phpc.social
    wrote last edited by
    #1

    #PHP is truly the gift that keeps on giving: https://3v4l.org/aapUB
    ```php
    $a = ["min", "max", "crazy", "shit"];
    var_dump(min($a));
    ```
    => `string(5) "crazy"`

    Should also work with other comparable types such as DateTime objects.

    wyri@toot-toot.wyrihaxim.usW saramg@fosstodon.orgS 2 Replies Last reply
    0
    • girgias@phpc.socialG girgias@phpc.social

      #PHP is truly the gift that keeps on giving: https://3v4l.org/aapUB
      ```php
      $a = ["min", "max", "crazy", "shit"];
      var_dump(min($a));
      ```
      => `string(5) "crazy"`

      Should also work with other comparable types such as DateTime objects.

      wyri@toot-toot.wyrihaxim.usW This user is from outside of this forum
      wyri@toot-toot.wyrihaxim.usW This user is from outside of this forum
      wyri@toot-toot.wyrihaxim.us
      wrote last edited by
      #2

      @Girgias but why 😱

      girgias@phpc.socialG 1 Reply Last reply
      0
      • wyri@toot-toot.wyrihaxim.usW wyri@toot-toot.wyrihaxim.us

        @Girgias but why 😱

        girgias@phpc.socialG This user is from outside of this forum
        girgias@phpc.socialG This user is from outside of this forum
        girgias@phpc.social
        wrote last edited by
        #3

        @wyri It uses `<=>` under the hood effectively to "sort and filter" the min/max value.

        derickr@phpc.socialD 1 Reply Last reply
        0
        • girgias@phpc.socialG girgias@phpc.social

          @wyri It uses `<=>` under the hood effectively to "sort and filter" the min/max value.

          derickr@phpc.socialD This user is from outside of this forum
          derickr@phpc.socialD This user is from outside of this forum
          derickr@phpc.social
          wrote last edited by
          #4

          @Girgias @wyri Makes perfect sense to me. Seems like a useful feature.

          george@phpc.socialG 1 Reply Last reply
          0
          • derickr@phpc.socialD derickr@phpc.social

            @Girgias @wyri Makes perfect sense to me. Seems like a useful feature.

            george@phpc.socialG This user is from outside of this forum
            george@phpc.socialG This user is from outside of this forum
            george@phpc.social
            wrote last edited by
            #5

            @derickr @Girgias @wyri I really like it for dates… saves throwing a pointless closure at `usort`. I wouldn't use it for strings tho 🤷‍♂️

            1 Reply Last reply
            0
            • girgias@phpc.socialG girgias@phpc.social

              #PHP is truly the gift that keeps on giving: https://3v4l.org/aapUB
              ```php
              $a = ["min", "max", "crazy", "shit"];
              var_dump(min($a));
              ```
              => `string(5) "crazy"`

              Should also work with other comparable types such as DateTime objects.

              saramg@fosstodon.orgS This user is from outside of this forum
              saramg@fosstodon.orgS This user is from outside of this forum
              saramg@fosstodon.org
              wrote last edited by
              #6

              @Girgias What's wild is how long this has worked and I've never even thought to try it. https://3v4l.org/YF8KK#v4.3.0

              Square brackets changed to array() because THAT'S HOW OLD THIS BEHAVIOR IS. IT PREDATES SHORT ARRAY SYNTAX.

              Link Preview Image
              ekes@drupal.communityE 1 Reply Last reply
              0
              • saramg@fosstodon.orgS saramg@fosstodon.org

                @Girgias What's wild is how long this has worked and I've never even thought to try it. https://3v4l.org/YF8KK#v4.3.0

                Square brackets changed to array() because THAT'S HOW OLD THIS BEHAVIOR IS. IT PREDATES SHORT ARRAY SYNTAX.

                Link Preview Image
                ekes@drupal.communityE This user is from outside of this forum
                ekes@drupal.communityE This user is from outside of this forum
                ekes@drupal.community
                wrote last edited by
                #7

                @saramg @Girgias Not that I'd ever thought to try it, but I checkd it is the documented behaviour, since at least 2005 https://web.archive.org/web/20050204040528/http://us4.php.net/min It can take an array as single argument. Will use standard comparison rules. With added caution about mixing types. Accidentally having you numeric string in there cast to an int is going to throw things. But potentially pretty handy I have to agree.

                1 Reply Last reply
                1
                0
                • R relay@relay.mycrowd.ca shared this topic
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups