Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2006
    Posts
    63

    PHP arrays newby

    Hey guys I have a problem here with a script that i want to build

    Ajax and arrays are new things 4 me

    $country=$_POST[country];
    $allstates = array(
    "AF"=>array("Badakhshan", "Badghis", "Baghlan", "Balkh", "Bamian", "Daykondi", "Farah", "Faryab", "Ghazni", "Ghowr", "Helmand", "Herat", "Jowzjan", "Kabul", "Kandahar", "Kapisa", "Khost", "Konar", "Kondoz", "Laghman", "Lowgar", "Nangarhar", "Nimruz", "Nurestan", "Oruzgan", "Paktia", "Paktika", "Panjshir", "Parvan", "Samangan", "Sar-e Pol", "Takhar", "Vardak", "Zabol"),
    "AL"=>array("Berat", "Dibres", "Durres", "Elbasan", "Fier", "Gjirokastre", "Korce", "Kukes", "Lezhe", "Shkoder", "Tirane", "Vlore"),
    ......... ))


    foreach ($allstates as $v1)
    {
    if(substr_count($country, $v1) === 1)
    {
    foreach ($v1 as $v2)
    {
    $resp=$resp."$v2\n";
    }
    }


    if(substr_count($country, $v1) === 1) <- Here is the error what's the correct function to select "AF" , "AG" <- country code

    User will send using this $country=$_POST[country]; the country code and script will return the states/region of that country ..

    Please help me

  2. #2
    Join Date
    Nov 2004
    Location
    HK
    Posts
    309
    I dont understand what's your substr_count() for...

    PHP Code:
    foreach($allstates[$country] as $states)
    {
    // your code goes here

    Rails in DA - Ruby on Rails plugin for Directdmin | DA-Tomcat - Tomcat Manager plugin for Directdmin
    DA-PgSQL - PostgreSQL plugin for Directdmin | IP Deny Manager - IP Deny Manager plugin for Directdmin
    DeeperAdmin - Manager your DirectAdmin server "deeper"
    Order now at http://www.daplugin.com

  3. #3
    Join Date
    Apr 2006
    Posts
    63

Posting Permissions

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