我有此代码:
return Carbon::createFromFormat('Y-m-d', $given_date, $user_timezone)->next($user_day); // $user_day = 'Monday';
给出错误:
未定义索引:星期一
感谢您的任何帮助。
通过查看函数本身:
// Carbon\CarbonInterface
/**
* Modify to the next occurrence of a given modifier such as a day of
* the week. If no modifier is provided, modify to the next occurrence
* of the current day of the week. Use the supplied constants
* to indicate the desired dayOfWeek, ex. static::MONDAY.
*
* @param string|int|null $modifier
*
* @return static
*/
public function next($modifier = null);
您可以得出您需要使用碳常数,即Carbon::MONDAY
。查看类本身,解析为1
。
因此,您还可以将0
(星期日)到6
(星期六)的任何整数传递。