let say I have one array ($results) containing arrays (location, start_date, coord_lng, coord_lat etc...). The idea is that I would like to sort $result by start_date which is pretty simple using array_multisort. Where it is becoming more difficult is that all other arrays (location, coord_lng, coord_lat etc) should be reorganized the same way and I don't know how to do it !
looking at solution provided here: PHP: Sort multi-dimension array I am not sure how to adapt to more than 2 arrays...
I have produced this code but is there anything quicker ?
foreach ($row['table'] as $key2 => $row2)
{
if($key2 != 'debut')
{
$dates = $results[$key]['table']['debut'];
array_multisort($dates, SORT_ASC, $results[$key]['table'][$key2]);
}
}
$dates = $results[$key]['table']['debut'];
array_multisort($dates, SORT_ASC, $results[$key]['table']['debut']);
$row2
by reference (by using&
in the loop iteration, like$key2 => &$row2
). Then you can manipulate$row2
directly instead of calling$results[$key]['table'][$key2]
. That being said, I don't think the savings will be particularly huge, though your code will be a little easier to understand.