#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"`Should also work with other comparable types such as DateTime objects.
-
#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.
@Girgias but why

-
@Girgias but why

@wyri It uses `<=>` under the hood effectively to "sort and filter" the min/max value.
-
@wyri It uses `<=>` under the hood effectively to "sort and filter" the min/max value.
-
-
#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.
@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.

-
@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.

@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.
-
R relay@relay.mycrowd.ca shared this topic
️