php-pdo代码,用日期附加no


php pdo code to append no with date

列名

优惠券

偶联态

开始日期

我正在生成基于优惠券和开始日期的coupondate。

对于EX-

如果优惠券=500501,开始日期=2015年2月24日

然后coupongate生成如下。。

coupondate=23-03-2015

但我需要附加优惠券和coupondate

对于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); 

尝试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>";