RE: [PHP] rates for differents date?

From: Date: Fri, 07 Mar 2003 11:30:21 +0000
Subject: RE: [PHP] rates for differents date?
Groups: php.general 
Request: Send a blank email to php-general+get-138603@lists.php.net to get a copy of this message
Hi Shaine, > ok question: 7days in a week. > day 1-2 costs $10, > day 3-5 cost $15, > day 4-7 costs $10. I'm assuming you meant 6-7 here instead of 4-7, otherwise you've introduced a contradiction with days 3-5. > how can I work out the total if someone stays from say day 2-5? > or what about day 3-7? Try this: <?php // assume $start holds start day // assume $end holds end day // note that the first array element is "0" - this is // because day 0 doesn't exist :-) $costs = array(0, 10, 10, 15, 15, 15, 10, 10); $total = 0; for ($i = $start; $i <= $end; $i++) $total += $costs[$i]; echo "<p>Total is $total.</p>"; ?> Working out how to change it so people can stay from day 6 in week 1 to day 4 in week 2 is left as an exercise for the reader ;-) Cheers Jon

« previous php.general (#138603) next »