Increment values in multidimensional array from exploded string

-=[OmD]=-

New Member
With a string such as: \[code\]"Sydney, New South Wales, Australia"\[/code\] I am trying to extract the comma separated values and add them to an array where state name and city name are the \[code\]keys\[/code\] and the total number of times that each appears in the result set is the \[code\]value\[/code\] - ideally, I'd like each city nested under the state. My current code is:\[code\]while ($row = $result->fetch(PDO::FETCH_ASSOC)) { $locname = explode(", ",$row['name']); $states[$locname[1]] +=1; $states[$locname[1]][$locname[0]] +=1;}\[/code\]This correctly returns the state, but does not create the \[code\]key\[/code\] for each city. Am I missing something obvious or can someone suggest a more elegant solution?
 
Back
Top