http://us3.php.net/manual/en/array.sorting.php

 

Andrew 

 

From: [email protected] [mailto:[email protected]] On Behalf
Of Aaron Cooper
Sent: Tuesday, 28 July 2009 9:00 a.m.
To: [email protected]
Subject: [phpug] Sorting Multidimensional Array on values of multiple keys

 

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




__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4282 (20090727) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

 


--~--~---------~--~----~------------~-------~--~----~
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[email protected]
-~----------~----~----~----~------~----~------~--~---

Reply via email to