php計算優惠資訊 求計算演算法 多謝

來源:互聯網
上載者:User
php計算優惠資訊 求計算演算法 謝謝
PHP code
$arr=array('item_info_list' => Array                                (                                    '0' => Array                                        (                                            'sku_id' => '1003244250',                                            'ware_id' => '1001418658',                                            'jd_price' => '269.00',                                            'sku_name' => '百事PEPSI 男式板鞋 2012新款夏季透氣舒適男款經典休閑板鞋 獵人綠 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' => '百事PEPSI 男式板鞋 2012新款夏季透氣舒適男款經典休閑板鞋 暗紅 39',                                            'outer_sku_id' => '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' => '30-單品促銷優惠',                                            'coupon_price' => '170.00',                                        )                                    ,                                    '1' => Array                                        (                                            'order_id' => '213978711',                                            'sku_id' => '1003244255',                                            'coupon_type' => '30-單品促銷優惠',                                            'coupon_price' => '170.00',                                        )                                ))


求計算實際價格的演算法 有時候'item_info_list' 子數組裡只有一個商品 'coupon_detail_list' 子數組裡只有一個優惠資訊
而有時候候'item_info_list' 子數組裡只有一個商品 'coupon_detail_list' 子數組裡沒有優惠資訊,有時候'item_info_list' 子數組裡只有兩個商品 'coupon_detail_list' 子數組裡只有一個優惠資訊,有時候'item_info_list' 子數組裡只有兩個商品 'coupon_detail_list' 子數組裡有兩個優惠資訊, 求大神指導 !




------解決方案--------------------
你最後想要什麼結果。
------解決方案--------------------
//先預先處理一下
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";

------解決方案--------------------
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);
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.