...

View Full Version : Is an array the right option for this?



pcproff
11-15-2011, 04:17 AM
Hi all,

I am using the $_GET method to create a variable called $statename. That variable serves as a value for certain files such as $statename.pdf etc.

We are now having regional files that we need to show depending on what state they land on. So my question is: Is an array the right thing to use here? I have about 30 arrays to create if that is the case. The script will detect what the value of $statename is check which array is tied to $statename and serve the correct file. Any simpler option?


$a = array(
'LA County',
'Orange County',
'San Bernadino County'
)

$b = array(
'Broward County',
'Dade County',
'Palm Beach County'
)

timgolding
11-15-2011, 12:50 PM
Associative arrays is the way to go

e.g



$a = array(
'LA County' =>'filename.htm',
'Orange County' => 'filname2.htm',
'San Bernadino County' => 'filename3.htm'
);

pcproff
11-22-2011, 03:54 PM
Hi there thanks for the response! This is what I did as an include file. The key here was to query the DB to get this list out with the associative syntax and format already in place.



$country_array = array(
'afghanistan' => 'afghanistanandpakistan',
'albania' => 'balkans',
'algeria' => 'northwestafrica',
'americansamoa' => 'pacificocean',
'andorra' => 'loweranddenmark',
'angola' => 'southernafrica',
'antarctica' => 'antarctica',
'antiguaandbarbuda' => 'westindies',
'argentina' => 'southernsouthamerica',
'armenia' => 'thecaucasus',
'australia' => 'australia',
'austria' => 'alps',
'azerbaijan' => 'thecaucasus',
'bahamas' => 'westindies',
'bahrain' => 'arabianpeninsula',
'bangladesh' => 'southasia',
'barbados' => 'westindies',
'belarus' => 'europeanrussia',
'belgium' => 'loweranddenmark',
'belize' => 'centralnorthamerica',
'benin' => 'northwestafrica',
'bhutan' => 'southasia',
'bolivia' => 'nwcentralamerica',
'bosniaandherzegovina' => 'balkans',
'botswana' => 'southernafrica',
'brazil' => 'easternsouthamerica',
'brunei' => 'southeasternasia',
'bulgaria' => 'balkans',
'burkinafaso' => 'northwestafrica',
'burundi' => 'northeastafrica',
'cambodia' => 'indochina',
'cameroon' => 'northwestafrica',
'canada' => 'canada',
'capeverde' => 'africa',
'centralafricanrepublic' => 'northwestafrica',
'chad' => 'northwestafrica',
'chile' => 'southernsouthamerica',
'china' => 'china',
'colombia' => 'nwcentralamerica',
'comoros' => 'africa',
'congobrazzaville' => 'southernafrica',
'congokinshasa' => 'southernafrica',
'costarica' => 'centralnorthamerica',
'croatia' => 'balkans',
'cuba' => 'westindies',
'cyprus' => 'easternmediterranean',
'czechrepublic' => 'centraleurope',
'denmark' => 'scandinavia',
'djibouti' => 'hornofafrica',
'dominica' => 'westindies',
'dominicanrepublic' => 'westindies',
'easttimor' => 'southeasternasia',
'ecuador' => 'nwcentralamerica',
'egypt' => 'northeastafrica',
'elsalvador' => 'centralnorthamerica',
'equatorialguinea' => 'southernafrica',
'eritrea' => 'hornofafrica',
'estonia' => 'scandinavia',
'ethiopia' => 'hornofafrica',
'faroeislands' => 'scandinavia',
'fiji' => 'pacificocean',
'finland' => 'scandinavia',
'france' => 'france',
'frenchpolynesia' => 'pacificocean',
'gabon' => 'southernafrica',
'gambia' => 'northwestafrica',
'georgia' => 'thecaucasus',
'germany' => 'germany',
'ghana' => 'northwestafrica',
'greece' => 'greece',
'greenland' => 'greenland',
'grenada' => 'westindies',
'guam' => 'pacificocean',
'guatemala' => 'centralnorthamerica',
'guinea' => 'northwestafrica',
'guineabissau' => 'northwestafrica',
'guyana' => 'nwcentralamerica',
'haiti' => 'westindies',
'honduras' => 'centralnorthamerica',
'hongkong' => 'chinacoast',
'hungary' => 'balkans',
'iceland' => 'scandinavia',
'india' => 'southasia',
'indonesia' => 'southeasternasia',
'iran' => 'iraqandiran',
'iraq' => 'iraqandiran',
'ireland' => 'britishisles',
'israel' => 'easternmediterranean',
'italy' => 'italy',
'ivorycoast' => 'northwestafrica',
'jamaica' => 'centralnorthamerica',
'japan' => 'japan',
'jordan' => 'middleeast',
'kazakhstan' => 'centralasia',
'kenya' => 'northeastafrica',
'kiribati' => 'pacificocean',
'kosovo' => 'balkans',
'kuwait' => 'arabianpeninsula',
'kyrgyzstan' => 'centralasia',
'laos' => 'indochina',
'latvia' => 'europeanrussia',
'lebanon' => 'easternmediterranean',
'lesotho' => 'southernafrica',
'liberia' => 'northwestafrica',
'libya' => 'northwestafrica',
'liechtenstein' => 'loweranddenmark',
'lithuania' => 'centraleurope',
'luxembourg' => 'france',
'macedonia' => 'balkans',
'madagascar' => 'southernafrica',
'malawi' => 'southernafrica',
'malaysia' => 'southeasternasia',
'maldives' => 'southasia',
'mali' => 'northwestafrica',
'malta' => 'loweranddenmark',
'marshallislands' => 'pacificocean',
'mauritania' => 'northwestafrica',
'mauritius' => 'africa',
'mexico' => 'mexico',
'micronesia' => 'pacificocean',
'moldova' => 'balkans',
'monaco' => 'loweranddenmark',
'mongolia' => 'china',
'montenegro' => 'balkans',
'montserrat' => 'westindies',
'morocco' => 'northwestafrica',
'mozambique' => 'southernafrica',
'myanmar' => 'indochina',
'namibia' => 'southernafrica',
'nauru' => 'pacificocean',
'nepal' => 'southasia',
'netherlands' => 'loweranddenmark',
'newcaledonia' => 'pacificocean',
'newzealand' => 'newzealand',
'nicaragua' => 'centralnorthamerica',
'niger' => 'northwestafrica',
'nigeria' => 'northwestafrica',
'niue' => 'pacificocean',
'northkorea' => 'koreanpeninsula',
'norway' => 'scandinavia',
'oman' => 'arabianpeninsula',
'pakistan' => 'afghanistanandpakistan',
'palau' => 'pacificocean',
'panama' => 'centralnorthamerica',
'papuanewguinea' => 'papuanewguinea',
'paraguay' => 'southernsouthamerica',
'peru' => 'nwcentralamerica',
'philippines' => 'southeasternasia',
'poland' => 'centraleurope',
'portugal' => 'spainandportugal',
'puertorico' => 'westindies',
'qatar' => 'arabianpeninsula',
'romania' => 'balkans',
'russia' => 'russia',
'rwanda' => 'northeastafrica',
'saintkittsandnevis' => 'westindies',
'saintlucia' => 'westindies',
'saintvincentandthegrenadines' => 'westindies',
'samoa' => 'pacificocean',
'sanmarino' => 'loweranddenmark',
'saotomeandprincipe' => 'africa',
'saudiarabia' => 'arabianpeninsula',
'senegal' => 'northwestafrica',
'serbia' => 'balkans',
'seychelles' => 'africa',
'sierraleone' => 'northwestafrica',
'singapore' => 'southeasternasia',
'slovakia' => 'centraleurope',
'slovenia' => 'balkans',
'solomonislands' => 'pacificocean',
'somalia' => 'hornofafrica',
'southafrica' => 'southernafrica',
'southkorea' => 'koreanpeninsula',
'spain' => 'spainandportugal',
'srilanka' => 'southasia',
'sudan' => 'northeastafrica',
'suriname' => 'easternsouthamerica',
'swaziland' => 'southernafrica',
'sweden' => 'scandinavia',
'switzerland' => 'alps',
'syria' => 'middleeast',
'taiwan' => 'chinacoast',
'tajikistan' => 'centralasia',
'tanzania' => 'southernafrica',
'thailand' => 'indochina',
'togo' => 'northwestafrica',
'tonga' => 'pacificocean',
'trinidadandtobago' => 'centralnorthamerica',
'tunisia' => 'northwestafrica',
'turkey' => 'middleeast',
'turkmenistan' => 'centralasia',
'tuvalu' => 'pacificocean',
'uganda' => 'northeastafrica',
'ukraine' => 'europeanrussia',
'unitedarabemirates' => 'arabianpeninsula',
'unitedkingdom' => 'britishisles',
'unitedstatesofamerica' => 'unitedstates',
'uruguay' => 'southernsouthamerica',
'usvirginislands' => 'westindies',
'uzbekistan' => 'centralasia',
'vanuatu' => 'pacificocean',
'vaticancity' => 'loweranddenmark',
'venezuela' => 'nwcentralamerica',
'vietnam' => 'indochina',
'westbankandgaza' => 'easternmediterranean',
'yemen' => 'arabianpeninsula',
'zambia' => 'southernafrica',
'zimbabwe' => 'southernafrica'
);


After that I just echo $country_array[$country];?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum