Home  >  Article  >  Backend Development  >  How to get and display the day of the week in php

How to get and display the day of the week in php

藏色散人
藏色散人Original
2021-03-10 09:16:172796browse

php implements the method of getting the displayed day of the week: first create a PHP sample file; then define an array, and get the day of the week through "date("w")"; and finally perform display processing.

How to get and display the day of the week in php

#The operating environment of this article: Windows7 system, PHP7.1, Dell G3 computer.

php obtains the displayed day of the week through the date function

A simple PHP method to display the day of the week. To determine what day of the week today is, you can know the day of the week through the following Several operations.

echo date("l");//date就可以获取英文的星期比如Sunday
echo date("w");//这个可以获取数字星期比如123,注意0是星期日

You can define an array, get the day of the week through date("w"), and then display the processing

$weekarray=array("日","一","二","三","四","五","六"); //先定义一个数组
echo "星期".$weekarray[date("w")];

You can also specify the day of the week by adding a second parameter, Then it is displayed.

$weekarray=array("日","一","二","三","四","五","六"); //先定义一个数组
echo "星期".$weekarray[date("w","2016-03-03")];

Recommended: "PHP Video Tutorial"

The above is the detailed content of How to get and display the day of the week in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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