Getting method: 1. Define the "array("7","1","2","3","4","5","6")" array; 2. Use " date("w",strtotime("specified date"))" converts the date into a number representing the week; 3. Use the number as a subscript and retrieve the corresponding day value from the array.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php Get the day of the week that the specified date is
Determine the day of the week that the specified date is, that is, determine the day of the week that the specified date is.
We can use date("w",strtotime("specified date"))
to achieve this; but the return value of this statement is: a number representing the day of the week (0 represents Sunday[ Sunday], 6 means Saturday [Saturday]).
We can create an array as follows:
array("七","一","二","三","四","五","六")
Use the return value of the above date() statement as a subscript, and then take out the corresponding day of the week value in the array.
Let’s take a look at the implementation code:
<?php header('content-type:text/html;charset=utf-8'); $weekarray=array("7","1","2","3","4","5","6"); echo "一周的第 ".$weekarray[date("w",strtotime("2021-11-29"))]." 天<br>"; echo "一周的第 ".$weekarray[date("w",strtotime("2021-11-30"))]." 天<br>"; echo "一周的第 ".$weekarray[date("w",strtotime("2021-12-1"))]." 天<br>"; ?>
PHP Video Tutorial》
The above is the detailed content of How to get the day of the week for a specified date in php. For more information, please follow other related articles on the PHP Chinese website!