I have some JSON data that I have sorted by "sites" using usort
usort($data,function($a,$b) {
return strnatcasecmp($a['site'],$b['site']);
});
Which results in the following
Array (
[0] => Array
(
[time] => 2017-07-15 15:43:45
[user] => ast125
[site] => facebook
)
[1] => Array
(
[time] => 2017-07-12 04:59:11
[user] => ast111
[site] => facebook
)
[2] => Array
(
[time] => 2017-07-19 12:45:14
[user] => ast133
[site] => facebook
)
[3] => Array
(
[time] => 2017-07-19 12:45:14
[user] => ast133
[site] => google
)
[4] => Array
(
[time] => 2017-07-19 12:45:14
[user] => ast125
[site] => facebook
)
.... and so on
I'm stuck because now I'm not sure how to approach sorting the users per site. Right now, the order is
facebook - ast125
facebook - ast111
facebook - ast133
google - ast133
google - ast125
But I would like the users to be sorted while in their site group
facebook - ast111
facebook - ast125
facebook - ast133
google - ast125
google - ast133
Right now, I am considering breaking the JSON array into multiple arrays (by site), and then sort the new site array by users, and then merge them back into one...
Is there an easier way for me to approach this using usort or another PHP function?