Results 1 to 3 of 3
Thread: PHP arrays newby
-
12-21-2006, 10:40 AM #1Junior Guru Wannabe
- 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
-
12-21-2006, 10:53 AM #2Web Hosting Guru
- Join Date
- Nov 2004
- Location
- HK
- Posts
- 310
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
-
12-21-2006, 09:57 PM #3Junior Guru Wannabe
- Join Date
- Apr 2006
- Posts
- 63
Thanks it worked