我有一个数组(变量 $items),其中有相同的 invenid(多个)如何检查是否有多个 invenid 以及如何从每个现有数组添加 total_price 并创建一个新的键为 discount_price。这是我的数组:
function apply_promotion($items){
foreach($items as $key => $val){
if(isset($val['promo'])){
$promo_type = $val['promo']['slug'];
$start_date = $val['promo']['startdate'];
$end_date = $val['promo']['enddate'];
if(($start_date != '0000-00-00') && ($end_date != '0000-00-00') && (strtotime(timetodate(DT_TIME, 3)) >= strtotime($start_date)) && (strtotime(timetodate(DT_TIME, 3)) <= strtotime($end_date))){
switch($promo_type){
case "item-promotion":
$purchase = dround($val['total_price'], 2, 1);
if($purchase >= $val['promo']['min_purchase'] && empty($val['promo_code'])){
$items[$key]['discount_price']= dround($val['promo']['discount_amount'], 2, 1);
}
break;
}
}
}
}
echo '<pre>'.print_r($items, 1).'</pre>';die();
return $items;
}
慕田峪4524236
慕仙森
眼眸繁星