我需要编写一个 php 脚本,根据用户注册的日期确定用户必须支付的金额。他们注册得越晚,支付的费用就越多,所以这里是脚本的基本代码:
private $date;
function __construct() {
$this->date = getdate();
}
function get_amount()
{
$day = $this->date["mday"];
$month = $this->date["month"];
$year = $this->date["year"];
$date = $day.$month.$year;
switch($date) {
case "26October2012":
return "800";
break;
case "26Novermber2012":
return "900";
break;
}
}
但显然这个 case 语句不能正常工作。因此,如果用户在 2012 年 10 月 26 日之前注册,那么他们支付 800,如果是在 11 月 26 日之前但在 10 月 26 日之后,那么他们支付 900。那么我该如何编写这个逻辑呢?