Php computing discount information, calculation algorithm. thank you!

Source: Internet
Author: User
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); 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.