Php computing discount information calculation algorithm Thank you PHPcode $ arrarray (item_info_list & gt; Array (0 & gt; Array php computing discount information calculation algorithm thank you
PHP code
$ Arr = array ('item _ info_list '=> Array ('0' => Array ('sku _ id' => '123 ', 'Ware _ id' => '000000', 'JD _ price' => '2017. 00', 'sku _ name' => 'Pepsi PEPSI men's shoes 2012 new summer breathable and comfortable men's classic casual shoes hunter green 40', 'outer _ sku_id '=> '123 ', 'product _ no' => '2014 872121101 872121102 872121104 872121105 ', 'gift _ point' => '0', 'item _ total' => '1 ',), '1' => Array ('sku _ id' => '000000', 'Ware _ id' => '000000', 'JD _ price' => '2017. 00', 'sku _ name' => 'Pepsi PEPSI men's shoes 2012 new summer breathable and comfortable men's classic casual shoes dark red 39 ', 'outer _ sku_id' => '123 ', 'product _ no' => '2014 872121101 872121102 872121104 872121105 ', 'gift _ point' => '0', 'item _ total' => '1 ',)), 'coupon _ detail_list '=> Array ('0' => Array ('Order _ id' => '123', 'sku _ id' => '123 ', & apos; coupon _ type & apos; = & apos; 30 & apos;, & apos; coupon _ price & apos; = & apos; 170 & apos. 00',), '1' => Array ('Order _ id' => '123', 'sku _ id' => '123 ', & apos; coupon _ type & apos; = & apos; 30 & apos;, & apos; coupon _ price & apos; = & apos; 170 & apos. 00 ',)))
The algorithm used to calculate the actual price. sometimes there is only one item in the 'item _ info_list 'sub-array that has only one item in the 'upon _ detail_list' sub-array.
Sometimes, there is only one item in the 'item _ info_list 'subarray that has no discount information, sometimes, the 'item _ info_list 'sub-array contains only one preferential information in the 'items _ detail_list' sub-array, sometimes, the 'item _ info_list 'sub-array contains only two commodity 'upon _ detail_list' sub-arrays with two discount information!
------ Solution --------------------
What is the final result you want.
------ Solution --------------------
// Preprocessing
Foreach ($ arr ['item _ info_list '] as $ v) $ item_info_list [$ v ['sku _ id'] = $ v;
Foreach ($ arr ['coupon _ detail_list '] as $ v) $ coupon_detail_list [$ v ['sku _ id'] = $ v;
Foreach ($ item_info_list as $ k => $ v)
Echo "sku_id: $ k price:". isset ($ coupon_detail_list [$ k])? $ Coupon_detail_list [$ k] ['coupon _ price']: $ v ['JD _ price'],"
\ N ";
------ Solution --------------------
PHP code
foreach ($arr['item_info_list'] as $key=>$val){ if(isset($arr['coupon_detail_list'][$key])) $arr['item_info_list'][$key] = array_merge($val, $arr['coupon_detail_list'][$key]);}print_r($arr);