我正在尝试制作一个脚本,以便在一年中的特定日期、月份等触发。所以我决定使用switch,因为我有3个案例。我希望它能每周、每月和每季度触发。以下是我到目前为止所做的
$date=date('l,m,Y');
switch($date) {
case (date('l')=="Monday"): //case 1:he should trigger every Monday
echo 'weekly';
break;
case (date('d')==01): //case 2:he should trigger every 01 or 1 of each month
echo "monthly";
break;
case ...: //case 3:here i need some help...it should trigger every 3 months(quarterly),at the first day(01 or 1) after the quart
因此,为了使这个开关工作,我需要格式化$date,换句话说,使用date_format将l改为d等等。但它不工作。。。因为要使用date_format,我还必须使用date_create
$date = strtotime("6 Oct 2014"); //change this with "now" value
if (date('l', $date) == 'Monday'){}//if its monday,execute
if (date('d', $date) == "06"){}//if its 06 of the month,execute
if ( ((date('n',$date) % 3) == '1') && (date('d',$date) == "06") ){}// if its 06 of the month,and has passed 3 months(quarterly),execute
将代码放入每个"if"语句中,如果所有3个条件都通过,它将执行3次。