title: How to convert this PHP array ina working price calculation?
body: <p>Here comes the tricky part<br>
  In a rent application, I have arrays like this (of course array size and values may vary):</p>
  
  <pre><code>$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; // |
  </code></pre>
  
  <p>The keys are the rent days, and the values are the # of items rent by a user for a specific product</p>
  
  <p>Days are all consecutive (I yet grouped adjacent days with <a href="https://stackoverflow.com/questions/17729552">another script</a>)</p>
  
  <p>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</p>
  
  <p>As you can see, in this example a total of 5 items are rent for the dates' range:</p>
  
  <ol>
  <li>item 1 for 1 week and 2 spare days (15-16-17-18-19-20-21)<br>
  echo total price: 1*W + 2*D</li>
  <li>item 2 for 1 week and 1 spare day (15-16-17-18-19-20)<br>
  echo total price: 1*W + 1*D</li>
  <li>item 3 for 3 spare days (17-18-19)<br>
  echo total price: 0*W + 3*D</li>
  <li>item 4 for 2 spare days (17-19)<br>
  echo total price: 0*W + 2*D</li>
  <li>item 5 for 1 day (17)<br>
  echo total price: 0*W + 1*D</li>
  </ol>
  
  <p>... and sum all of the above</p>
  
  <p>Ok, so far so good: I can express the concept in words</p>
  
  <p>But... how to translate this into a script? Really difficult to me!</p>
  
  <p>Many thanks in advance!</p>
  
  <p><strong>EDIT</strong>: 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:</p>
  
  <ul>
  <li>2 "Vacuum Cleaner Brand-X" on 2013-07-15</li>
  <li>2 "Vacuum Cleaner Brand-X" on 2013-07-16</li>
  <li>5 "Vacuum Cleaner Brand-X" on 2013-07-17</li>
  <li>etc...</li>
  </ul>
  
  <p>Oozel answer make sense! In order to work with my example, I just have to slightly modify his script like this:</p>
  
  <pre><code>foreach ($dates as $items){
      for ($i=1; $i&lt;=$items; $i++){
          ... 
      }
  }
  </code></pre>
  
  <p>@oozel: I have a number (and not an array of items) 'cause of the specific UI</p>
  
  <p>Oversemplifying:</p>
  
  <pre><code>Vacuum Cleaner Brand-X
  Calendar
  July 2013
  ...
  &lt;td&gt;
      15&lt;br&gt;
      &lt;input type="checkbox" title="Activate this day" value="2013-07-15"&gt;
      &lt;select title="Choose how many Vacuum Cleaner Brand-X to be rent on this day"&gt;
          &lt;option&gt;1&lt;/option&gt;
          ...
          &lt;option&gt;10&lt;/option&gt;
      &lt;/select&gt;
  &lt;/td&gt;
  &lt;td&gt;
      16&lt;br&gt;
      &lt;input type="checkbox" title="Activate this day" value="2013-07-16"&gt;
      &lt;select title="Choose how many Vacuum Cleaner Brand-X to be rent on this day"&gt;
          &lt;option&gt;1&lt;/option&gt;
          ...
          &lt;option&gt;10&lt;/option&gt;
      &lt;/select&gt;
  &lt;/td&gt;
  &lt;td&gt;
      17&lt;br&gt;
      &lt;input type="checkbox" title="Activate this day" value="2013-07-17"&gt;
      &lt;select title="Choose how many Vacuum Cleaner Brand-X to be rent on this day"&gt;
          &lt;option&gt;1&lt;/option&gt;
          ...
          &lt;option&gt;10&lt;/option&gt;
      &lt;/select&gt;
  &lt;/td&gt;
  
  ...
  </code></pre>