Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2006
    Posts
    71
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Is an array the right option for this?

    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?

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

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


  • #2
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    Associative arrays is the way to go

    e.g

    PHP Code:
    $a = array(
    'LA County' =>'filename.htm',
    'Orange County' => 'filname2.htm',
    'San Bernadino County' => 'filename3.htm'
    ); 
    You can not say you know how to do something, until you can teach it to someone else.

  • Users who have thanked timgolding for this post:

    pcproff (11-22-2011)

  • #3
    New Coder
    Join Date
    Nov 2006
    Posts
    71
    Thanks
    12
    Thanked 0 Times in 0 Posts
    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.

    PHP Code:
    $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];?>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •