[php smart class schedule] Select the day of the week in a certain date range and get the date corresponding to the day of the week

little bottle
Release: 2023-04-06 07:40:02
forward
2468 people have browsed it

I recently used this in a curriculum project. There is a date range. After selecting the day of the week, I want to get the date corresponding to the selected week in this date range, as shown below, and the code is as follows


function getDateByWeek($data)
{    $start_date = strtotime($data['start_date']);    $end_date = strtotime($data['end_date']);    $days = ($end_date - $start_date) / 86400;    $weekArr = array('周日','周一','周二','周三','周四','周五','周六');    $newDate = array();    // 组建数组格式 $dataWeek['日期'] => 星期
    for ($i=0; $i < $days; $i++) { 
        $num_week = date('w',$start_date+($i*86400));        $dateWeek[date('Y-m-d',$start_date+($i*86400))] = $weekArr[$num_week];
    }    // 查找两个数组的交集,即获取提交的星期对应的日期
    $newDate=array_intersect($dateWeek,$data['items']);    // 获取数组中的键值(日期),并组成一个新数组
    $date = array_keys($newDate);    return $date;
}
Copy after login

Related tutorials: PHP video tutorial

The above is the detailed content of [php smart class schedule] Select the day of the week in a certain date range and get the date corresponding to the day of the week. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template