列名称
优惠券
coupondate
STARTINGDATE
我根据优惠券和开始日期生成优惠券。
FOR EX -
如果优惠券= 500,501且起始日期= 24-02-2015
然后coupondate产生如下..
coupondate = 23-03-2015,23-04-2015
但我需要使用优惠券追加优惠券
FOR EX -
500 - 23-03-2015
501 - 23-04-2015喜欢明智..
plz帮助获得以上输出
下面是我的代码
$coupon = $_POST['coupon'];
$startingdate = $_POST['startingdate'];
$coupons = explode(',', $coupon);
$dates = Array();
for ($no = 1; $no < count($coupons) + 1; $no++)
{
$dates[] = date("d-m-Y", strtotime($startingdate . " +" . $no . " MONTHS -1 DAYS"));
}
$coupondate = implode(',', $dates);
答案 0 :(得分:0)
尝试使用foreach而不是for循环,并将优惠券代码与日期一起附加。
$coupon = $_POST['coupon'];
$startingdate = $_POST['startingdate'];
$coupons = explode(',', $coupon);
$dates = Array();
$no = 1;
foreach($coupons as $coupon) {
$dates[] = $coupon . " - " . date("d-m-Y", strtotime($startingdate . " +" . $no . " MONTHS -1 DAYS"));
$no++;
}
$coupondate = implode(',', $dates);
echo "<pre>";
print_r($coupondate); //out put you required
echo "</pre>";