我有一个数组(变量 $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; }
3 回答
慕田峪4524236
TA贡献1875条经验 获得超5个赞
您可以使用foreachwith pass by reference
foreach($a as $key => &$val){
($val['invenid'] > 1) ? ($val['total_price'] = 12.00) : '';
}
- 3 回答
- 0 关注
- 117 浏览
添加回答
举报
0/150
提交
取消