Re: Array mysteries

From: Date: Sun, 11 Mar 2007 09:14:09 +0000
Subject: Re: Array mysteries
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-250218@lists.php.net to get a copy of this message
At 9:51 AM +0100 3/11/07, Otto Wyss wrote:
I want to convert weekdays with a simple function like $wdays = array
    (0 => "Sonntag"
    ,1 => "Montag"
    ,2 => "Dienstag"
    ,3 => "Mittwoch"
    ,4 => "Donnerstag"
    ,5 => "Freitag"
    ,6 => "Samstag"
); function convert_from_weekday ($weekday) {
    return $wdays[$weekday];
} but this doesn't work while $wdays[$weekday]; outside of the function works correct. Has anybody an idea where's my mistake? I'd like to use a function so I may return substrings of the weekday.
If the above is your exact code, then the problem is one of scope; move the $wdays declaration inside your convert_from_weekday() function. However, you may want to investigate the formatting functions of date(): http://php.he.net/manual/en/function.date.php Date should return names using the native locale; if you want to return date strings for other locales/languages, use setlocale() - http://php.he.net/manual/en/function.setlocale.php - and strftime() - http://php.he.net/manual/en/function.strftime.php I think you'll find your work has been at least partially done for you. And, see http://php.he.net/manual/en/language.variables.scope.php for more information on variable scope. steve -- +--------------- my people are the people of the dessert, ---------------+ | Steve Edberg http://pgfsun.ucdavis.edu/ | | UC Davis Genome Center sbedberg@ucdavis.edu | | Bioinformatics programming/database/sysadmin (530)754-9127 | +---------------- said t e lawrence, picking up his fork ----------------+

« previous php.general (#250218) next »