Jump to content

Stdclass Object.. Need To Sort By Ip And Then By Date Within Ip


Recommended Posts

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,

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.