Re: convert numerical day of week

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 5/22/07, Daniel Brown <parasane@xxxxxxxxx> 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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux