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]))