RE: [PHP] simplify if/then statement
$incfilename = Calc.$state..class.inc; if (file_exists($incfilename)) include($incfilename); else echo Please select a State.br\n; -- Stuart -Original Message- From: Jim Long [mailto:[EMAIL PROTECTED]] Sent: 27 April 2002 20:00 To: php Subject: [PHP] simplify if/then statement Hi, I've got the following statement for a state options menu. How can this be expressed in a simple manner for all 52 states? //choose state if ($state == AL) { // include class include(CalcAL.class.inc); } else if ($state == AR) { // include class include(CalcAR.class.inc); } else if ($state == AZ) { // include class include(CalcAZ.class.inc); } else{ echo Please select a State.br\n; } Thank You Very Much, Jim Long -- http://jimlong.net/web -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] simplify if/then statement
On Sunday 28 April 2002 02:59, Jim Long wrote: Hi, I've got the following statement for a state options menu. How can this be expressed in a simple manner for all 52 states? //choose state if ($state == AL) { // include class include(CalcAL.class.inc); } else if ($state == AR) { Take a look at the switch construct. -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* Parsley is gharsley. -- Ogden Nash */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] simplify if/then statement
On Sat, 27 Apr 2002, Jim Long wrote: I've got the following statement for a state options menu. How can this be expressed in a simple manner for all 52 states? switch(strtolower($state)) { case 'al': include 'CalcALclass.inc'; break; case 'ar': include 'CalcALclass.inc'; break; } Or, really, just: include Calc{$state}class.inc; miguel //choose state if ($state == AL) { // include class include(CalcAL.class.inc); } else if ($state == AR) { // include class include(CalcAR.class.inc); } else if ($state == AZ) { // include class include(CalcAZ.class.inc); } else{ echo Please select a State.br\n; } Thank You Very Much, Jim Long -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] simplify if/then statement
I'd do something similar to this, along with putting all states in an array to make sure $state is actually a state (in_array). And maybe you want to add guam :) a) be sure $state is set, else load default b) be sure $state is not bogus, else yell at them c) be sure the $state file exists, if so, include it else houston we have a problem Regards, Philip Olson On Sat, 27 Apr 2002, Stuart Dallas wrote: $incfilename = Calc.$state..class.inc; if (file_exists($incfilename)) include($incfilename); else echo Please select a State.br\n; -- Stuart -Original Message- From: Jim Long [mailto:[EMAIL PROTECTED]] Sent: 27 April 2002 20:00 To: php Subject: [PHP] simplify if/then statement Hi, I've got the following statement for a state options menu. How can this be expressed in a simple manner for all 52 states? //choose state if ($state == AL) { // include class include(CalcAL.class.inc); } else if ($state == AR) { // include class include(CalcAR.class.inc); } else if ($state == AZ) { // include class include(CalcAZ.class.inc); } else{ echo Please select a State.br\n; } Thank You Very Much, Jim Long -- http://jimlong.net/web -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] simplify if/then statement
Hi, Make an array $arr of all the states and loop $state = AR; $arr = array(); array_push($arr, AL, AR, AZ); foreach ($arr as $key = $value) { if ($state == $value){ include(Calc$value.class.inc); } } Cheers, Pekka http://photography-on-the.net/ At 4/27/2002, you wrote: Hi, I've got the following statement for a state options menu. How can this be expressed in a simple manner for all 52 states? //choose state if ($state == AL) { // include class include(CalcAL.class.inc); } else if ($state == AR) { // include class include(CalcAR.class.inc); } else if ($state == AZ) { // include class include(CalcAZ.class.inc); } else{ echo Please select a State.br\n; } Thank You Very Much, Jim Long -- http://jimlong.net/web -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] simplify if/then statement
On Sat, 27 Apr 2002, Philip Olson wrote: I'd do something similar to this, along with putting all states in an array to make sure $state is actually a state (in_array). And maybe you want to add guam :) As an early Christmas present, here's the array (to save the OP some typing - I'm posting this to the list because I use it a lot and assume it'd be handy for others too). Uses USPS 2-letter abbreviations and includes territories. $states = array( 'AK' = 'Alaska', 'AL' = 'Alabama', 'AR' = 'Arkansas', 'AS' = 'American Samoa', 'AZ' = 'Arizona', 'CA' = 'California', 'CO' = 'Colorado', 'CT' = 'Connecticut', 'DC' = 'District of Columbia', 'DE' = 'Delaware', 'FL' = 'Florida', 'GA' = 'Georgia', 'GU' = 'Guam', 'HI' = 'Hawaii', 'IA' = 'Iowa', 'ID' = 'Idaho', 'IL' = 'Illinois', 'IN' = 'Indiana', 'KS' = 'Kansas', 'KY' = 'Kentucky', 'LA' = 'Louisiana', 'MA' = 'Massachusetts', 'MD' = 'Maryland', 'ME' = 'Maine', 'MH' = 'Marshall Islands', 'MI' = 'Michigan', 'MN' = 'Minnesota', 'MO' = 'Missouri', 'MP' = 'Northern Mariana Islands', 'MS' = 'Mississippi', 'MT' = 'Montana', 'NC' = 'North Carolina', 'ND' = 'North Dakota', 'NE' = 'Nebraska', 'NH' = 'New Hampshire', 'NJ' = 'New Jersey', 'NM' = 'New Mexico', 'NV' = 'Nevada', 'NY' = 'New York', 'OH' = 'Ohio', 'OK' = 'Oklahoma', 'OR' = 'Oregon', 'PA' = 'Pennsylvania', 'PR' = 'Puerto Rico', 'RI' = 'Rhode Island', 'SC' = 'South Carolina', 'SD' = 'South Dakota', 'TN' = 'Tennessee', 'TX' = 'Texas', 'UT' = 'Utah', 'VA' = 'Virginia', 'VI' = 'Virgin Islands (U.S.)', 'VT' = 'Vermont', 'WA' = 'Washington', 'WI' = 'Wisconsin', 'WV' = 'West Virginia', 'WY' = 'Wyoming'); miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] simplify if/then statement
Using pull down for $state. This works great! $incfilename = Calc.$state..class.inc; if (file_exists($incfilename)) include($incfilename); else echo Please select a State.br\n; Thanks To Everyone, j -- http://jimlong.net/web I'd do something similar to this, along with putting all states in an array to make sure $state is actually a state (in_array). And maybe you want to add guam :) a) be sure $state is set, else load default b) be sure $state is not bogus, else yell at them c) be sure the $state file exists, if so, include it else houston we have a problem -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php