Here comes the tricky part
In a rent application, I have arrays like this (of course array size and values may vary):
$dates = array();
// each "pipe" | is an item for visual help
$dates['2013-07-15'] = 2; // ||
$dates['2013-07-16'] = 2; // ||
$dates['2013-07-17'] = 5; // |||||
$dates['2013-07-18'] = 3; // |||
$dates['2013-07-19'] = 4; // ||||
$dates['2013-07-20'] = 2; // ||
$dates['2013-07-21'] = 1; // |
The keys are the rent days, and the values are the # of items rent by a user for a specific product
Days are all consecutive (I yet grouped adjacent days with another script)
5 consecutive days are considered a "working week", and special price applies: let's say D is the daily price and W is the weekly price
As you can see, in this example a total of 5 items are rent for the dates' range:
- item 1 for 1 week and 2 spare days (15-16-17-18-19-20-21)
echo total price: 1*W + 2*D - item 2 for 1 week and 1 spare day (15-16-17-18-19-20)
echo total price: 1*W + 1*D - item 3 for 3 spare days (17-18-19)
echo total price: 0*W + 3*D - item 4 for 2 spare days (17-19)
echo total price: 0*W + 2*D - item 5 for 1 day (17)
echo total price: 0*W + 1*D
... and sum all of the above
Ok, so far so good: I can express the concept in words
But... how to translate this into a script? Really difficult to me!
Many thanks in advance!
EDIT: to clarify, values for each array item represents the number of items of that specific product rent by user; let's say product is "Vacuum Cleaner Brand-X" and there are 10 items in the shop's stock; the cleaning company "Your-Clean-House inc." got a big deal and, in this case, is going to rent:
- 2 "Vacuum Cleaner Brand-X" on 2013-07-15
- 2 "Vacuum Cleaner Brand-X" on 2013-07-16
- 5 "Vacuum Cleaner Brand-X" on 2013-07-17
- etc...
Oozel answer make sense! In order to work with my example, I just have to slightly modify his script like this:
foreach ($dates as $items){
for ($i=1; $i<=$items; $i++){
...
}
}
@oozel: I have a number (and not an array of items) 'cause of the specific UI
Oversemplifying:
Vacuum Cleaner Brand-X
Calendar
July 2013
...
<td>
15<br>
<input type="checkbox" title="Activate this day" value="2013-07-15">
<select title="Choose how many Vacuum Cleaner Brand-X to be rent on this day">
<option>1</option>
...
<option>10</option>
</select>
</td>
<td>
16<br>
<input type="checkbox" title="Activate this day" value="2013-07-16">
<select title="Choose how many Vacuum Cleaner Brand-X to be rent on this day">
<option>1</option>
...
<option>10</option>
</select>
</td>
<td>
17<br>
<input type="checkbox" title="Activate this day" value="2013-07-17">
<select title="Choose how many Vacuum Cleaner Brand-X to be rent on this day">
<option>1</option>
...
<option>10</option>
</select>
</td>
...