note 126392 added to control-structures.match
| From: | Anonymous at main dot php dot net | Date: | Mon, 06 Sep 2021 10:37:06 +0000 |
| Subject: | note 126392 added to control-structures.match | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-216869@lists.php.net to get a copy of this message | ||
<?php
function days_in_month(string $month): int
{
return match(strtolower(substr($name, 0, 3))) {
'jan' => 31,
'feb' => is_leap($year) ? 29 : 28,
'mar' => 31,
'apr' => 30,
'may' => 31,
'jun' => 30,
'jul' => 31,
'aug' => 31,
'sep' => 30,
'oct' => 31,
'nov' => 30,
'dec' => 31,
default => throw new InvalidArgumentException("Bogus month"),
};
}
?>
can be more concisely written as
<?php
function days_in_month(string $month): int
{
return match(strtolower(substr($name, 0, 3))) {
'apr', 'jun', 'sep', 'nov' => 30,
'jan', 'mar', 'may', 'jul', 'aug',
'oct', 'dec' => 31,
'feb' => is_leap($year) ? 29 : 28,
default => throw new InvalidArgumentException("Bogus month"),
};
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.85.242 (proxied: 83.49.210.156)
----
Manual Page -- https://php.net/manual/en/control-structures.match.php
Edit -- https://main.php.net/note/edit/126392
Del: integrated -- https://main.php.net/note/delete/126392/integrated
Del: useless -- https://main.php.net/note/delete/126392/useless
Del: bad code -- https://main.php.net/note/delete/126392/bad+code
Del: spam -- https://main.php.net/note/delete/126392/spam
Del: non-english -- https://main.php.net/note/delete/126392/non-english
Del: in docs -- https://main.php.net/note/delete/126392/in+docs
Del: other reasons-- https://main.php.net/note/delete/126392
Reject -- https://main.php.net/note/reject/126392
Search -- https://main.php.net/manage/user-notes.php