Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Dan Soendergaard
March 25, 2008, 6:37 pm
rate this thread
I'm sure there is a simple solution to this problem, although it
sounds rather complex. I have an array of Entry objects with the
fields: ip, date (unix time), name. So, the array might contain this
000.000.000.000 987678 hello
001.001.001.001 558821 hello
000.000.000.000 287999 something
What I want to do is to sort the array of objects by a field.
Essentially, I'd like something like:
Is there a way to do this in PHP, or do I have to write a function
myself? If yes, do you have any suggestions on how to do this?
Also, is there a way to make array_count_values() and array_unique()
operate on fields in objects?
Thank you very much in advance!
Re: Count the number of unique values of field in object in array
You would have to write your own function and use it with usort().
Not really, but you could wrap the entire list into an object and add a
method to return a particular column from the list, e.g.
would return an array containing all IP addresses, the parameter 1 would
return an array with all timestamps, 2 all the names. This would allow
you to use a lot of array functions on just a particular column. Even
the sorting could then probably be done with array_multisort().
- » How to fix mail() double line spacing in message body?
- — Next thread in » PHP Scripting Forum