Hi
Hopefully a simple question..
The variable $day equals the numbers 0 to 6. 0 is Sunday, 6 is Saturday.
Is there a simple way to output $day and format it to show Sunday, Monday etc.
Thanks 🙂
This works :
switch($day) { case "0": $day = "Sunday"; break; case "1": $day = "Monday"; break; case "2": $day = "Tuesday"; break; case "3": $day = "Wednesday"; break; case "4": $day = "Thursday"; break; case "5": $day = "Friday"; break; case "6": $day = "Saturday"; break; }
But only on $day, how would I re write that so I could use it on multiple variables ?
I also need to do something similar with months !
Many Thanks
I would create one ARRAY with 7 daynames
<?php $dnames = array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"); $day = 2; // Tuesday echo $dnames[$day]; echo '<br />'; $day = 0; // Sunday echo $dnames[$day];
Put it in a function 🙂
Actually, this might be simpler:
$day_names = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); // now use $day_names[$day]
You can also make use of [man]mktime/man and [man]date/man with the w format character.
Thanks 🙂 How do I do that with Months ?? Jan = 1, Feb = 2
Thanks Again
Hmm.. this seems to work 🙂
$dmonths = array("","January","February","March","April","May","June","July","August","September","October","November","December");
Is that the right way ?? using a blank entry for 0 ??
Thanks
Mad_T wrote:Is that the right way ?? using a blank entry for 0 ??
That is fine, yes. You could also just subtract 1 or use date('F', mktime(0, 0, 0, $month)).
By the way, I think that $dnames is an insufficiently descriptive name, and indeed by using $dmonths instead of $mnames you have confirmed this. I suggest naming the array $month_names instead.
Thanks.
The naming changes your suggesting make sense 🙂
You're welcome 🙂 Remember to mark this thread as resolved (if it is) using the thread tools.