I'd like to take an array with this structure:
array
'Alabama' =>
array
0 =>
array
'id' => string '11' (length=2)
'region_name' => string 'Alabama' (length=7)
'city' => string 'Birmingham' (length=10)
1 =>
array
'id' => string '12' (length=2)
'region_name' => string 'Alabama' (length=7)
'city' => string 'Huntsville' (length=10)
2 =>
array
'id' => string '13' (length=2)
'region_name' => string 'Alabama' (length=7)
'city' => string 'Mobile' (length=6)
3 =>
array
'id' => string '14' (length=2)
'region_name' => string 'Alabama' (length=7)
'city' => string 'Montgomery' (length=10)
'Alaska' =>
array
0 =>
array
'id' => string '15' (length=2)
'region_name' => string 'Alaska' (length=6)
'city' => string 'Anchorage' (length=9)
And create unordered lists in html, like so:
<ul id="A">
<li class="state">Alabama</li>
<li>Birmingham</li>
<li>Huntsville</li>
<li>Mobile</li>
<li>Montgomery</li>
<li class="state">Alaska</li>
<li>Anchorage</li>
</ul>
<ul id="C">
<li class="state">California</li>
<li>Bakersfield</li>
<li>Fresno</li>
<li>Los Angeles</li>
</ul>
<ul id="D">
<li class="state">DC</li>
<li>Washington</li>
</ul>
The idea is an alphabetically ordered and grouped series of unordered lists, which I can show and hide easily using javascript. That part is easy... This part, I'm lost.
I've tried a sort of nested foreach loop, but the framework I'm using refused to do it citing OutputEscaper errors, which I believe made sense - I really am not sure how to do this properly.
I'd appreciate any help!
edit: Here's how the array is initially formatted:
$this->cityGroups = array();
foreach($this->USCities as $city)
{
$this->cityGroups[$city['region_name']][] = $city;
}
array('State 1' => array('City 1', 'City 2', 'City 3'), 'State 2'=>array('City 1', 'City 2', 'City 3'));