Hi all,
I remember from java, that an array containing objects with the method compareTo implemented to define a sequence order, could be sorted by the standard array sorting function. I've been looking for a similar functionality/method in PHP, and was wondering if anyone here knows anything?
Cheers,
Thomas
Sorting arrays
Moderator: General Moderators
Re: Sorting arrays
This is the 2 dimensional sorting function, may this will help you.
Code: Select all
function sort_array($array, $key, $order)
{
if ($order=="DESC")
$or="arsort";
else
$or="asort";
for ($i = 0; $i < sizeof($array); $i++)
{
$sort_values[$i] = $array[$i][$key];
}
$or($sort_values);
reset ($sort_values);
while (list ($arr_key, $arr_val) = each ($sort_values))
{
$sorted_arr[] = $array[$arr_key];
}
return $sorted_arr;
}