Home Backend Development PHP Tutorial php计算优惠信息 求计算算法 多谢

php计算优惠信息 求计算算法 多谢

Jun 13, 2016 pm 01:31 PM
gt list

php计算优惠信息 求计算算法 谢谢

PHP code

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

<!--

 

Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/

 

-->$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',

                                        )

 

                                )

)

Copy after login


求计算实际价格的算法 有时候'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

1

2

3

4

5

6

7

8

9

10

11

12

13

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

 <div class="clear">

                  

               

               

         

            </div>

Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Fix: Snipping tool not working in Windows 11 Fix: Snipping tool not working in Windows 11 Aug 24, 2023 am 09:48 AM

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

How to implement Redis List operation in php How to implement Redis List operation in php May 26, 2023 am 11:51 AM

List operation //Insert a value from the head of the list. $ret=$redis->lPush('city','guangzhou');//Insert a value from the end of the list. $ret=$redis->rPush('city','guangzhou');//Get the elements in the specified range of the list. 0 represents the first element of the list, -1 represents the last element, and -2 represents the penultimate element. $ret=$redis->l

How to convert JSONArray to List in Java How to convert JSONArray to List in Java May 04, 2023 pm 05:25 PM

1: JSONArray to ListJSONArray string to List//Initialize JSONArrayJSONArrayarray=newJSONArray();array.add(0,"a");array.add(1,"b");array.add(2,"c") ;Listlist=JSONObject.parseArray(array.toJSONString(),String.class);System.out.println(list.to

How to Fix Can't Connect to App Store Error on iPhone How to Fix Can't Connect to App Store Error on iPhone Jul 29, 2023 am 08:22 AM

Part 1: Initial Troubleshooting Steps Checking Apple’s System Status: Before delving into complex solutions, let’s start with the basics. The problem may not lie with your device; Apple's servers may be down. Visit Apple's System Status page to see if the AppStore is working properly. If there's a problem, all you can do is wait for Apple to fix it. Check your internet connection: Make sure you have a stable internet connection as the "Unable to connect to AppStore" issue can sometimes be attributed to a poor connection. Try switching between Wi-Fi and mobile data or resetting network settings (General > Reset > Reset Network Settings > Settings). Update your iOS version:

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

How to convert list to numpy How to convert list to numpy Nov 22, 2023 am 11:29 AM

Method to convert list to numpy: 1. Use the numpy.array() function. The first parameter of the function is a list object, which can be a one-dimensional or multi-dimensional list; 2. Use the numpy.asarray() function, which will try its best to Use the data type of the input list; 3. Use the numpy.reshape() function to convert the one-dimensional list into a multi-dimensional NumPy array; 4. Use the numpy.fromiter() function, the first parameter of the function is an iterable object.

Why doesn't list.sort() return a sorted list in Python? Why doesn't list.sort() return a sorted list in Python? Sep 18, 2023 am 09:29 AM

Example In this example, we first look at the usage of list.sort() before continuing. Here, we have created a list and sorted it in ascending order using sort() method - #CreatingaListmyList=["Jacob","Harry","Mark","Anthony"]#DisplayingtheListprint("List=",myList)#SorttheListsinAscendingOrdermyList .sort(

See all articles