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

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

藏色散人
Release: 2023-03-08 15:00:01
Original
2844 people have browsed it

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是星期日
Copy after login

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")];
Copy after login

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")];
Copy after login

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!

Related labels:
php
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