Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP echo all days of week (strftime)

I was wondering if there is a way to use the locale in strftime to echo all days of the week, regardless of date. To use as sort of headings or titles and rather than using constants and loading the correct one.

i.e.

setlocale(LC_TIME, "de_DE");
echo strftime("%A", 1); //echos Monday
echo strftime("%A", 2); //echos Tuesday
echo strftime("%A", 3); //echos Wednesday

so that all I need to do is change the locale for a different language.

Thanks

like image 978
Stevanicus Avatar asked Dec 07 '25 12:12

Stevanicus


2 Answers

setlocale(LC_TIME, "de_DE");
echo strftime("%A", strtotime("next Sunday"));
echo strftime("%A", strtotime("next Monday"));
echo strftime("%A", strtotime("next Tuesday"));
echo strftime("%A", strtotime("next Wednesday"));
echo strftime("%A", strtotime("next Thursday"));
echo strftime("%A", strtotime("next Friday"));
echo strftime("%A", strtotime("next Saturday"));
like image 181
malonso Avatar answered Dec 09 '25 02:12

malonso


You could alternatively create a simple for loop:

for ($i=0;$i<7;$i++) {
      $weekday[] = strftime('%a ', mktime(0, 0, 0, 6, $i+2, 2013));
    }
print_r($weekday);
like image 21
Remi Avatar answered Dec 09 '25 02:12

Remi