获取给定输入的月份从一周中的哪一天开始


Get which day of the week the month starts on for given input

我有一个函数来定义当前月份的星期几开始:

public function firstDayOfMonth()
    {
        $day =  (int) date("w", strtotime(date('m').'/01/'.date('Y').' 00:00:00'));
        return $day;
    }

我将如何更改上述内容,如果我输入它,例如"六月",我就可以获得月份开始的星期几。

您可以将代码简化为:

$month = 'June';
$day = (int) date('w', strtotime($month));
public function firstDayOfMonth($month) {
    $day =  (int) date("w", strtotime($month . ' 01,' . date('Y') . ' 00:00:00'));
    return $day;
}