Home > Backend Development > PHP Tutorial > Example program to get the day of the week in PHP_PHP tutorial

Example program to get the day of the week in PHP_PHP tutorial

WBOY
Release: 2016-07-13 10:48:22
Original
1008 people have browsed it

In PHP, if we want to get the day of the week today, we can directly use the date function to operate it. Let me summarize the specific operation method for you. I hope this method will be helpful to all my friends.

A brief introduction to how to get the day of the week in PHP, and the code to get the day of the week in PHP:

Get the Chinese day of the week:
The code is as follows
 代码如下 复制代码

1 date(“l”);

2 //data就可以获取英文的星期比如Sunday

3 date(“w”);

4 //这个可以获取数字星期比如123,注意0是星期日

Copy code

 代码如下 复制代码

1 $weekarray=array(“日”,“一”,“二”,“三”,“四”,“五”,“六”);

2 //先定义一个数组

3 echo “星期”.$weekarray[date(“w”)];

1 date(“l”);

2 //data can get the English day of the week such as Sunday
 代码如下 复制代码

1 $weekarray=array(“日”,“一”,“二”,“三”,“四”,“五”,“六”);

2 echo “星期”.$weekarray[date(“w”,“2011-11-11”)];

3 date(“w”);

 代码如下 复制代码


//php获取今天是星期几
function getWeek($unixTime=''){
$unixTime=is_numeric($unixTime)?$unixTime:time();
$weekarray=array('日','一','二','三','四','五','六');
return '星期'.$weekarray[date('w',$unixTime)];
}
echo getWeek();

4 //This can get the numerical day of the week, such as 123. Note that 0 is Sunday

代码如下 复制代码

function getWeek(){
$week = date("w");
switch($week){
case 1:
return "星期一";
break;
case 2:
return "星期二";
break;
case 3:
return "星期三";
break;
case 4:
return "星期四";
break;
case 5:
return "星期五";
break;
case 6:
return "星期六";
break;
case 0:
return "星期日";
break;
}
}
echo "今天是:".getWeek();
?>

The code is as follows Copy code
1 $weekarray=array("日", "一", "二", "三", "四", "五", "六"); 2 //Define an array first 3 echo “week”.$weekarray[date(“w”)]; Get the specified date:
The code is as follows Copy code
1 $weekarray=array("日", "一", "二", "三", "四", "五", "六"); 2 echo "week".$weekarray[date("w","2011-11-11")]; An example for my own use
The code is as follows Copy code

//php gets the day of the week today
function getWeek($unixTime=''){
$unixTime=is_numeric($unixTime)?$unixTime:time();
$weekarray=array('日','一','二','三','四','五','六');
return 'week'.$weekarray[date('w',$unixTime)];
}
echo getWeek();<🎜> <🎜> <🎜> <🎜> <🎜> or <🎜>
The code is as follows<🎜> Copy code<🎜> <🎜>
<🎜> function getWeek(){
$week = date("w");
switch($week){
case 1:
Return "Monday";
break;
case 2:
Return "Tuesday";
break;
case 3:
Return "Wednesday";
break;
case 4:
Return "Thursday";
break;
case 5:
Return "Friday";
break;
case 6:
Return "Saturday";
break;
case 0:
Return "Sunday";
Break;
}
}
echo "Today is:".getWeek();
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632809.htmlTechArticleIn php, if we want to get the day of the week today, we can directly use the date function to operate it. Let me give it to you students. Let’s summarize the specific operation methods. I hope this method will be helpful to all my friends...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template