I have seen many similar issues but none that can help explain my issue. I have an array called cities, with a nested array for the state that has the cities of that state. It looks like this:
$cities = array(
"ca" => array(
"los-angeles" => "Los Angeles"
),
"wa" => array(
"bellingham" => "Bellingham",
"seattle" => "Seattle",
"tacoma" => "Tacoma"
)
);
My PHP code to display many HTML select
fields:
<?php
foreach ($cities as $state) {
echo "<select name='city' id='" . $state . "'>";
foreach ($state as $city => $name) {
echo "<option value='" . $city . "'>" . $name . "</option>";
}
}
?>
The id
of the select
is always Array
. How can I use the key, like "ca" or "wa"?