列名
优惠券
偶联
开始日期
我正在根据优惠券和开始日期生成联票。
前 -
如果息票= 500,501和开始日期= 24-02-2015
然后联票产生如下..。
副主席= 23-03-2015,23-04-2015
,但我需要附加优惠券
前 -
500 - 23-03-2015
501 - 23-04-2015像wise.
请帮助获得以上输出。
下面是我的代码
$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); 发布于 2015-02-24 09:28:47
尝试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>";https://stackoverflow.com/questions/28691613
复制相似问题