On 3/11/07, Otto Wyss <[EMAIL PROTECTED]> 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.

O. Wyss


$wdays is not defined inside the function, so you can do a few things:
- Pass the $wdays inside the function:
function convert_from_weekday ($weekday,$wdays) {
   return $wdays[$weekday];
 }
$day = convert_from_weekday(0,$wdays) // $day = "Sonntag"

- You could define $wdays inside the function
function convert_from_weekday ($weekday,$wdays) {
$wdays = array
   (0 => "Sonntag"
   ,1 => "Montag"
   ,2 => "Dienstag"
   ,3 => "Mittwoch"
   ,4 => "Donnerstag"
   ,5 => "Freitag"
   ,6 => "Samstag"
 );
   return $wdays[$weekday];
 }
$day = convert_from_weekday(0) // $day = "Sonntag"
- If you are working from inside a class, you could define $wdays as a
public variable.

I think this solved your problem, but don't hesitate to ask for more!

Tijnema



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Reply via email to