直接上代碼
$date_you_want = match ($condition) {
'昨天' => date("Y-m-d", strtotime("-7 days", time())),
'上月' => date("Y-m-d", strtotime("-1 months", time())),
'去年' => date("Y-m-d", strtotime("-1 years", time())),
};如果想算下一天/月/年的, 就把-1改成+1, 以此類推。