Sorting By Value

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Pineriver
Forum Commoner
Posts: 50
Joined: Fri Aug 15, 2003 5:24 pm

Sorting By Value

Post by Pineriver »

How can I have a multidimential array sorted by value, not by key..

Code: Select all

#Sample code that I have already, making up the array.
while($i<10){
$people[$address][$i]=$unix_date;
$i++;
}
I am trying to sort through a text based log file where there are 2 fields, a unix time stamp and the address of a person.
The array is unique to each persons address but that person has multi counts of events which is recorded as a unix timestamp.

Code: Select all

[Address1] => Array
(
[19] => 1116263520
[20] => 1116263537
[22] => 1116265745
[23] => 1116265770
)

[Address2] => Array
(
[2] => 1116217275
[3] => 1116218023
[8] => 1116218035
[5] => 1116218076
[44] => 1116218087
)


I would like to have the final array sorted where the addresse's dates are sorted from first to the latest. So say if Address1 has the newest unix date that would come first in the array.
I almost figured this out but then I have a loop looping through the array that has to get the dates and addresses :x
Tell me if this makes sence and you can figure it out.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Have you tried using array_flip ?
Post Reply