RE: [PHP] Shipping Rates

From: Date: Tue, 03 Jun 2003 10:32:46 +0000
Subject: RE: [PHP] Shipping Rates
Groups: php.general 
Request: Send a blank email to php-general+get-149922@lists.php.net to get a copy of this message
> -----Original Message----- > From: Jim Lucas [mailto:phplist@zonedzero.net] > Sent: 02 June 2003 18:07 > To: Jim Lucas; Rasmus Lerdorf; Ralph > > Answering my own answer. I see now how you are extracting > the sub array > information. > > My mistake. Notwithstanding that, I think your question was a good one -- it seems to me that the use of a nested array is unnecessary complex for this application; if we go with your simplified simple array: > > > > $rates = array('7.45'=>20, > > '8.45'=>35, > > '9.45'=>55, > > '10.45'=>80, > > '11.45'=>100, > > '13.45'=>150, > > '15.55'=>200, > > '19.45'=>999999999); then the foraech can surely be written very simply like this: foreach($rates as $i => $vals) { if($num <= $vals) { $price = $i; break; } } return $price; Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: m.ford@lmu.ac.uk Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

« previous php.general (#149922) next »