[英]textual representation of day of the week from numeric representation
i need convert Numeric representation of the day of the week to textual representation of the day of the week. 我需要将星期几的数字表示形式转换为星期几的文本表示形式。
ex - 0 - sunday, 1 - monday 例如-0-星期日,1-星期一
date('w') -> date('l');
I can do it using simple array like this. 我可以使用像这样的简单数组来做到这一点。
$date = 1;
$dates = array(
0 => 'sunday',
1 => 'monday',
2 => 'tuesday',
3 => 'wednesday',
4 => 'thursday',
5 => 'friday',
6 => 'saturday',
);
echo $dates[$date]; //monday
But i need to know is this best way? 但是我需要知道这是最好的方法吗? How can i do it using php library function? 我该如何使用php库函数呢?
Improve the question. 改善问题。
I just find code like this. 我只是找到这样的代码。
echo date('l', strtotime(date('w')); //this code should invalid.
If you're just wanting the current day of the week you can just use the date function like so: date('l')
. 如果只需要星期几,可以使用date函数,例如: date('l')
。
If you're looking for a day of the week based on a specific number you provide than the way you show is a acceptable way to do it: 如果您要根据提供的特定数字查找一周中的某一天,那么显示的方式是可以接受的方式:
function dayFromNumber($day)
{
$dates = array(
0 => 'sunday',
1 => 'monday',
2 => 'tuesday',
3 => 'wednesday',
4 => 'thursday',
5 => 'friday',
6 => 'saturday',
);
return $dates[$day]
}
echo dayFromNumber(1); // Would echo monday
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.