Morning,
A challenge.
So I have this array, simple example as follows:
$testAry = array(
array('a' => 1, 'b' => 2, 'c' => 3),
array('a' => 2, 'b' => 1, 'c' => 3),
array('a' => 3, 'b' => 2, 'c' => 1),
array('a' => 1, 'b' => 3, 'c' => 2),
array('a' => 2, 'b' => 3, 'c' => 1),
array('a' => 3, 'b' => 1, 'c' => 2)
);
And I want to sort this array as in the same fashion as "ORDER BY" in sql
statements. So think of the array as a table with columns. In my particular
usage case, I would like order by 'a' primarily and 'b' secondarily.
I imagine the function call will look something like this:
orderBy($results_array, 'a ASC, b DESC');
Does anyone have a function to do this? I found a wrapper under usort() docs
but it doesn't seem to work, even with it's own test data.
And no, I can't do this at DB level unfortunately. The array in question is
built in various stages.
Cheers
Aaron
--~--~---------~--~----~------------~-------~--~----~
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[email protected]
-~----------~----~----~----~------~----~------~--~---