newbornultra Posted November 22, 2012 Share Posted November 22, 2012 Hi, in essence I am outputting some information into a Excel file. But I am stuck on how to sort some an array first by IP, and then within each IP sort it by date. I am pulling this information from a MySQL database, and adding it to an array of stfclass. $newListDetails=new StdClass; $newListDetails->topic=$row['topic_title']; $newListDetails->cat=$row['cat_name']; $newListDetails->ip=$row['ip_remote']; $newListDetails->search=$row['search']; $newListDetails->time=$row['time']; $newList[]=$newListDetails; And I am sorting them by IP like this: function sortByIp($a, $B){ return strcmp($a->ip, $b->ip); } usort($newList, 'sortByIp'); var_dump($newList); So it's grouping the IPs like I expect it to, but now I need to sort them by date within each IP. Does anyone have any ideas how to do that? Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/271023-stdclass-object-need-to-sort-by-ip-and-then-by-date-within-ip/ Share on other sites More sharing options...
trq Posted November 22, 2012 Share Posted November 22, 2012 Why don't you sort all your data in your query first? Quote Link to comment https://forums.phpfreaks.com/topic/271023-stdclass-object-need-to-sort-by-ip-and-then-by-date-within-ip/#findComment-1394330 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.