Re: convert numerical day of week
| From: | Greg Donald | Date: | Tue, 22 May 2007 17:13:36 +0000 |
| Subject: | Re: convert numerical day of week | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-255335@lists.php.net to get a copy of this message | ||
On 5/22/07, Daniel Brown <parasane@gmail.com> wrote:
<?
function num2day($num) {
if($num == "1") {
$day = "Sunday";
} elseif($num == "2") {
$day = "Monday";
} elseif($num == "3") {
$day = "Tuesday";
} elseif($num == "4") {
$day = "Wednesday";
} elseif($num == "5") {
$day = "Thursday";
} elseif($num == "6") {
$day = "Friday";
} elseif($num == "7") {
$day = "Saturday";
}
return $day;
}
?>
PHP does automatic type conversions, even if $num is passed in as a
string all those quotes around the integers are not necessary. There
is no variable interpolation required in the day names so all those
double quotes should be single quotes. A function call seems rather
heavy when a global array can be indexed more easily. Even a switch
statement would be an improvement.
--
Greg Donald
http://destiney.com/