我在我的一个脚本中运行了下面的代码,它运行得很好,但感觉很笨重,而且很长。我觉得可能有一个更短的方法来实现同样的结果。我也是说不用简略的if语句。
我需要弄清楚今天是否是星期四,如果不是以前一个星期四为日期。任何想法/想法都会很好。
<?php
if (new Carbon('this thursday') > new Carbon()) {
$date = Carbon('this thursday');
} else {
$date = Carbon('last thursday');
}
?>发布于 2015-07-02 16:31:00
根据http://carbon.nesbot.com/docs/#api-modifiers的说法:
$date将保存要显示的日期。
<?php
$today = new Carbon();
if($today->dayOfWeek == Carbon::THURSDAY)
$date = $today;
else
$date = new Carbon('last thursday');
?>https://stackoverflow.com/questions/31189700
复制相似问题