Hey all!
This little script works fine (iterating through MD array) in PHP5.2.5 on development server, but when I publish to production server (PHP5.1.6) it doesn't work (just loops through first sub -- over and over...). The problem appears to hinge on "$new_state= key($cities);" but I can't figure out why, and am stumped as to an alternative.
HELP!:eek:
P.S. You should be able to load this up and give it a whirl !
<?php
$state="AL";//start value
$city="auburn";//start value
if($_GET['state']){
$state=$_GET['state'];
$city=$_GET['city'];
}
$cities= Array(
'AL' => Array (
'1' => Array ( 'city' => 'auburn', 'url' => 'http://auburn.mydomain.com/'),
'2' => Array ( 'city' => 'birmingham', 'url' => 'http://bham.mydomain.com/'),
'3' => Array ( 'city' => 'columbus, GA', 'url' => 'http://columbusga.mydomain.com/')//border town
),
'AK' => Array ( 'city' => 'anchorage', 'url' => 'http://anchorage.mydomain.com/'),
'AZ' => Array (
'1' => Array ( 'city' => 'flagstaff / sedona', 'url' => 'http://flagstaff.mydomain.com/'),
'2' => Array ( 'city' => 'mohave cnty', 'url' => 'http://mohave.mydomain.com/')
)
);
foreach($cities as $key=>$value){
if($key != $state){continue;}//itterate until it does...
$count= count($value);
if($value['city']==''){ //e.g. more than one city this state...
foreach($value as $c_num=>$c_val){
if($c_val['city']!=$city){continue;}
else{//OPTION A
if($c_num< $count){//e.g more cities this state
$condition= "A";
$i=$c_num+1;
$new_city = $value[$i]['city'];
$new_url = $value[$i]['url'];
break;
}
else{//NEW STATE -- OPTION B
$condition= "B";
$new_state = key($cities);//WORKS on PHP5.2.5 development server, but not in PHP5.1.6 production
$new_city = $cities[$new_state]['1']['city'];
$new_url=$cities[$new_state]['1']['url'];
if($new_city==''){//e.g only ONE city this new_state
$condition= "B1";
$new_city=$cities[$new_state]['city'];
$new_url=$cities[$new_state]['url'];
}
break;
}
}
}
}//end if more than one city this state...
else{//only ONE city this state...
$condition= "C";
$new_state = key($cities);//WORKS on PHP5.2.5 development server, but not in PHP5.1.6 production
$new_city = $cities[$new_state]['1']['city'];
$new_url=$cities[$new_state]['1']['url'];
if($new_city==''){
$condition= "C1";
$new_city=$cities[$new_state]['city'];
$new_url=$cities[$new_state]['url'];
}
break;
}
}//end foreach $cities
if($new_state=='')$new_state=$state;
echo "CONDITION =".$condition."<br>";
echo "Previous State=".$state."<br>";
echo "Previous City=".$city."<br>";
echo "New State=".$new_state."<br>";
echo "New City=".$new_city."<br>";
echo "<a href='test.php?state=$new_state&city=$new_city'>Next Iteration</a>";
?>