PHP: getting weekdays numbers of a given month

巧了我就是萌 提交于 2019-12-04 19:27:04

Not very smart, but would works for you:

// sept. 2012
$month = 9;

// loop through month days
for ($i = 1; $i <= 31; $i++) {

    // given month timestamp
    $timestamp = mktime(0, 0, 0, $month, $i, 2012);

    // to be sure we have not gone to the next month
    if (date("n", $timestamp) == $month) {

        // current day in the loop
        $day = date("N", $timestamp);

        // if this is between 1 to 5, weekdays, 1 = Monday, 5 = Friday
        if ($day == 1 OR $day <= 5) {

            // write it down now
            $days[$day][] = date("j", $timestamp);
        }
    }
}

// to see if it works :)
print_r($days);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!