PHP Calculate preferential information calculation algorithm Thank you

Source: Internet
Author: User
PHP Calculation of preferential information calculation algorithm Thank you
PHP Code
  $arr =array (' item_info_list ' = = Array (' 0 ' = Arra                                            Y (' sku_id ' = ' 1003244250 ', ' ware_id ' = ' 1001418658 ', ' Jd_price ' =& Gt                                            ' 269.00 ', ' sku_name ' = ' pepsi pepsi Mens Board shoes 2012 New Summer breathable Comfort Mens Classic casual board shoes hunter Green 40 ', ' outer_sku_id ' = ' 40872121106 ', ' product                                            _no ' = ' 872121101 872121102 872121104 872121105 ', ' gift_point ' = ' 0 ',                                    ' Item_total ' = ' 1 ',)                             , ' 1 ' = = Array (               ' sku_id ' = ' 1003244255 ', ' ware_id ' = ' 1001418658 ', ' Jd_price ' = ' 269.00 ', ' Sku_name ' =&G T                                            ' Pepsi Pepsi Men's Board shoes 2012 new Summer breathable Comfort Mens Classic casual board shoes Crimson Red, ' outer_sku_id ' and ' 39872121105 ',                                            ' Product_no ' = ' 872121101 872121102 872121104 872121105 ',                                        ' Gift_point ' = ' 0 ', ' item_total ' = ' 1 ',                            )                                )                            ,                                        ' coupon_detail_list ' = = Array (' 0 ' = = array                                (' order_id ' = ' 213978711 ',            ' sku_id ' = ' 1003244250 ', ' coupon_type ' and ' 30-A-sale ',                                    ' Coupon_price ' = ' 170.00 ',)                                            , ' 1 ' = = Array ( ' order_id ' = ' 213978711 ', ' sku_id ' =& Gt                                            ' 1003244255 ', ' coupon_type ' + ' 30-promotional offers ', ' Coupon_price ' = ' 170.00 ',)))


An algorithm for calculating the actual price sometimes there is only one item in the ' Item_info_list ' sub-array ' coupon_detail_list ' sub-array there is only one offer information
And sometimes there is only one item in the ' Item_info_list ' sub-array ' coupon_detail_list ' subarray, there is no preferential information, sometimes ' item_info_list ' sub-array of only two items ' Coupon_detail_ There is only one preferential information in the list ' sub-array, sometimes there are only two items in the ' item_info_list ' sub-array ' coupon_detail_list ' sub-array there are two discount information, seeking the guidance of the Great God!




------Solution--------------------
What do you want to end up with?
------Solution--------------------
Just preprocess it.
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);
  • Related Article

    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.