I’m attempting to format data so that my json code can read it properly. The end result needs to look like the following:
[2][4][36] = 'Ohio'
Where ‘2’ is the region id, ‘4’ is the division id, and ’36’ is the state id. Obviously, there are many different results based upon which region and division is selected, but all the results need to be returned as per above.
The result I get from the code below only returns the last iteration. I’m wondering what I’m doing wrong:
$divisionCodeResults = array();
foreach($regionCodes as $key => $value){
$divisionCodeResults[$key] = $divisionTable->getDivisionResultsByRegionCode($key);
foreach($divisionCodeResults as $divValue){
$array_1 = array();
foreach($divValue as $divKey => $div2Value){
$array_1[$divKey] = $divKey;
$array_2 = array();
foreach($array_1 as $array_1_value){
$array_2[$key][$divKey] = Doctrine_Core::getTable('state')->getStatesIdAndNamesThatMatchDivisionKey($array_1_value);
}
}
}
}
The above var_dump() outputs the follwing:
array (size=1)
6 =>
array (size=1)
11 =>
array (size=2)
52 => string 'Puerto Rico' (length=11)
54 => string 'Virgin Islands' (length=14)
which is formatted correctly, but as stated, it is only returning the last iteration in a long multidimensional array.
Would appreciate an explanation of what I’m doing wrong… thanks in advance.
EDIT:
array (size=5)
2 =>
array (size=2)
4 => string 'East North Central' (length=18)
5 => string 'West North Central' (length=18)
3 =>
array (size=2)
2 => string 'New England' (length=11)
3 => string 'Mid-Atlantic' (length=12)
4 =>
array (size=3)
6 => string 'South Atlantic' (length=14)
7 => string 'East South Central' (length=18)
8 => string 'West South Central' (length=18)
5 =>
array (size=2)
9 => string 'Mountain' (length=8)
10 => string 'Pacific' (length=7)
6 =>
array (size=1)
11 => string 'Carribean' (length=9)
the above is the result of: var_dump($divisionCodeResults);
Move $array_1 and $array_2 outside of the loops, like: