![]() |
How to search array
I want to code a buy one get one free option on my site. Initially, I wrote it so that half of the number of products were free, based on the lowest prices. So, if three products were $200 each and three were $100 each, the three $100 ones would be free. But my customers quickly pointed out they were not really getting one free. It should have been one $200 and two $100 for free. That's where I am at now. I can't figure out how to determine which ones should be free. Here's some pseudo code showing what I am doing.
PHP Code:
Does anyone have any suggestions on how to tackle this problem? |
You mean something like this:
PHP Code:
Code:
Current selected items: |
Thank you for the code but that doesn't output the result I am looking for. I didn't think about it when I originally posted but I probably should have listed what the output should be, for this example, so I will do that now. Given the following array, there are seven entries, which means there should be three marked as free, since it's buy one get one.
PHP Code:
This one since it is the lowest price and not part of a pair (where a pair refers to items with the same model numbers) PHP Code:
PHP Code:
PHP Code:
PHP Code:
|
I just wanted to say that I figured this out. I ended up creating a master array before looping through the products. If a product is found, I then delete it from the master array and count the number of free products found. I have to iterate through the array more times that is probably necessay but it works. Thanks for trying to help.
|
| All times are GMT. The time now is 07:14 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0