Re: is this code decent?

From: Date: Wed, 22 Nov 2000 00:20:30 +0000
Subject: Re: is this code decent?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-26549@lists.php.net to get a copy of this message
Another alternative, possibly cleaner: unset($CostArray); $CostArray['Residential']['Qwest 640k/272k'] = '19.95'; $CostArray['Residential']['Qwest 640k/544k'] = '39.95'; ... ... $cost = $CostArray[$servicetype][$servicespeed]; if (!$cost) { $cost = 'Call for Price'; } ... This allows you to separate the data from the logic, making it easier to change the data without possibly forking up the logic. Also, it would be easier to modify the program in the future - for example, by putting the cost data into an include file, or by reading it from a database instead. An alternative $CostArray declaration would be: $CostArray = array( 'Residential' => array( 'Qwest 640k/272k' => '19.95', 'Qwest 640k/544k' => '39.95', 'Qwest 960k/816k'=> '59.95 ), 'SOHO' => array( ... ), ... ); This may be more or less understandable to you. See http://www.php.net/manual/language.types.array.php for more info. - steve At 1:29 PM -0800 11/21/00, Jerry Lake wrote:
I just want to get some opinions on whether or not my code looks decent (it works regardless) and if anyone has any advise on how to make it better, I'd appreciate it. <snip> <? // Begin Qwest Residential Pricing if ($servicespeed == 'Qwest 640k/272k' && $servicetype == 'Residential') { $cost = '19.95'; } elseif ($servicespeed == 'Qwest 640k/544k' && $servicetype == 'Residential') { $cost = '39.95'; } elseif ($servicespeed == 'Qwest 960k/816k' && $servicetype == 'Residential') { $cost = '59.95'; } elseif ($servicespeed == 'Qwest 1280k/1088k' && $servicetype == 'Residential') { $cost = '79.95'; } // Begin Qwest SOHO Pricing elseif ($servicespeed == 'Qwest 640k/272k' && $servicetype == 'SOHO') { $cost = '49.95'; } elseif ($servicespeed == 'Qwest 640k/544k' && $servicetype == 'SOHO') { $cost = '99.95'; } elseif ($servicespeed == 'Qwest 960k/816k' && $servicetype == 'SOHO') { $cost = '149.95'; } elseif ($servicespeed == 'Qwest 1280k/1088k' && $servicetype == 'SOHO') { $cost = '199.95'; } // Begin Qwest Business Pricing elseif ($servicespeed == 'Qwest 640k/272k' && $servicetype == 'Business') { $cost = '100.00'; } elseif ($servicespeed == 'Qwest 640k/544k' && $servicetype == 'Business') { $cost = '200.00'; } elseif ($servicespeed == 'Qwest 960k/816k' && $servicetype == 'Business') { $cost = '300.00'; } elseif ($servicespeed == 'Qwest 1280k/1088k' && $servicetype == 'Business') { $cost = '400.00'; } else { $cost = 'Call for Price'; } ?> </snip> Jerry Lake
+--- "They've got a cherry pie there, that'll kill ya" ------------------+
| Steve Edberg                           University of California, Davis |
| sbedberg@ucdavis.edu                               Computer Consultant |
| http://aesric.ucdavis.edu/                  http://pgfsun.ucdavis.edu/ |
+-------------------------------------- FBI Special Agent Dale Cooper ---+

« previous php.general (#26549) next »