I have the following result from a MySQL query with two joins.
Array (
[0] => Array ( [place_id] => 1 [place] => Berlin [lat] => 52.519 [lon] => 13.406 [id] => 1 [pname] => Firstschool [typ] => 0 [s_id] => 32 [fac] => history)
[1] => Array ( [place_id] => 1 [place] => Berlin [lat] => 52.519 [lon] => 13.406 [id] => 1 [pname] => Secondschool [typ] => 0 [s_id] => 33 [fac] => math)
[2] => Array ( [place_id] => 1 [place] => Berlin [lat] => 52.519 [lon] => 13.406 [id] => 1 [pname] => Secondschool [typ] => 0 [s_id] => 33 [fac] => english)
)
The data is redundant at some points, I need it this way:
Array (
[Berlin] => Array ( [lat] => 52.519
[lon] => 13.406
[schools] => Array([0]=> Firstschool [1]=>Secondschool)
)
[OtherCity] => Array ( ... )
)
First, is this okay or exists a better solution? =)
Second.. how to split it for the needed result.
I tried it with something like the following code snippet, but it doesn’t work as wished.
foreach($viewmodel as $item) {
$data[$item['place']][] = $item['pname'];
}
The result is:
Array ( [Berlin] => Array ( [0] => Firstschool [1] => Firstschool [2] => Firstschool ))
NOT so useful. 😉
I hope its understandable what I need. Maybe someone has an nice idea how to solve this problem.
Thanks for your time.
I think you are on a right path, just need to fill in a little more detail:
For the gather faculties too question, use the school names as keys to arrays in the ‘schools’ key of the top level arrays, populate them like this: (still skipping duplicates):