This seems like it would have a really easy solution...but I've had a hard time figuring it out. I need an array to go into a database. For example:
$usa = array(
'idaho' => array(
county1 => array(
'pocatello', 'arimo', 'downey'
),
county2 => array(
'bear', 'cuprum', 'mesa'
)
'iowa' => array(
county1 => array(
'des moines', 'adel', 'desoto'
),
county2 => array(
'douglas', 'grant', 'jasper'
)
);
I tried this method of inserting into the database:
foreach($usa as $state => $county){
foreach($county as $name => $city){
$s=$state;
$county_name = strtolower($name);
$city = strtolower($city);
$us = "INSERT INTO us
SET state='{$s}',county='{$county_name}',city='{$city}'
";
$us_result = mysql_query($us,$connection);
}
}
I believe the problem is the foreach (passing the state variable into the second foreach loop). I have tried this a number of different ways. Thanks in advance for your help!
***Note: everything works great when I remove the $s=$state variable and the state='{$s}' portion of the insert. I still cant get it to insert the state