This is a discussion on sort array by key within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi, What I want is simple, but I can't figure it out at the moment. Let's say this ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi,
What I want is simple, but I can't figure it out at the moment. Let's say this is an array names $matches: Array ( [0] => Array ( [teamid] => 137 [teamnaam] => Weet ik Veel ?? [speeldagid] => vr [speeldagvolgnr] => 5 ) [1] => Array ( [teamid] => 27 [teamnaam] => Tycoon [speeldagid] => di [speeldagvolgnr] => 2 ) [2] => Array ( [teamid] => 36 [teamnaam] => Arabier 1 [speeldagid] => do [speeldagvolgnr] => 4 ) [3] => Array ( [teamid] => 105 [teamnaam] => Road Runners [speeldagid] => do [speeldagvolgnr] => 4 ) ) And I want to sort it on key 'speeldagvolgnr', how do I do this? So I want the array back Array ( [0] => Array ( [teamid] => 27 [teamnaam] => Tycoon [speeldagid] => di [speeldagvolgnr] => 2 ) [1] => Array ( [teamid] => 36 [teamnaam] => Arabier 1 [speeldagid] => do [speeldagvolgnr] => 4 ) [2] => Array ( [teamid] => 105 [teamnaam] => Road Runners [speeldagid] => do [speeldagvolgnr] => 4 ) [3] => Array ( [teamid] => 137 [teamnaam] => Weet ik Veel ?? [speeldagid] => vr [speeldagvolgnr] => 5 ) ) I have looked at the sort functions at PHP.net, but could not find the solution. Can you help me out? Thanx. |
|
|||
|
Boefje wrote:
> I have looked at the sort functions at PHP.net, but could not find the > solution. > You have missed usort(): function cmp($a, $b) { if ($a['speeldagvolgnr'] == $b['speeldagvolgnr']) { return 0; } return ($a['speeldagvolgnr'] < $b['speeldagvolgnr']) ? -1 : 1; } usort($matches, "cmp"); JW |