Re: convert numerical day of week

From: Date: Tue, 22 May 2007 17:18:21 +0000
Subject: Re: convert numerical day of week
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-255336@lists.php.net to get a copy of this message
On 5/22/07, Greg Donald <gdonald@gmail.com> wrote:
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/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php You may have noticed my disclaimer at the head of the message. It was
there for just that reason.... -- Daniel P. Brown [office] (570-) 587-7080 Ext. 272 [mobile] (570-) 766-8107

« previous php.general (#255336) next »