Sorting Multidimensional Array by Specific Key?

I think you want something like this: usort($standings, function($a, $b) { return $b05 - $a05; }) Or prior to PHP 5.3: function cmp($a, $b) { return $b05 - $a05; } usort($standings, 'cmp') When using usort the $a and $b parameters will be one "layer" into the supplied array. So in your case, an example of $a or $b will be: 0 => Array ( 0 => cooller 1 => 6 2 => 6 3 => 0 4 => 0 5 => 18 ) I'm not sure why you have an extra containing array there, but as you can see, you want to sort based on the 05 position.

I think you want something like this: usort($standings, function($a, $b) { return $b05 - $a05; }); Or prior to PHP 5.3: function cmp($a, $b) { return $b05 - $a05; } usort($standings, 'cmp'); When using usort, the $a and $b parameters will be one "layer" into the supplied array. So in your case, an example of $a or $b will be: 0 => Array ( 0 => cooller 1 => 6 2 => 6 3 => 0 4 => 0 5 => 18 ) I'm not sure why you have an extra containing array there, but as you can see, you want to sort based on the 05 position.

Yea I think its the statement $standings = array($i => array("$name", $games, $win, $loss, $draw, $points)); found within my for-loop. I'm going to test this out ASAP and i'll let you know whats up. Thanks for your help.

: – lemonpole Jul 2 at 21:18 okay so I changed my previous statement to eliminate that extra array; so as you stated above it is now based on position 05. I used your method with usort and the custom compare function. There has been sorting but not in DESC order.

I got, 13, 25, 18, 18... I was thinking would a loop within the compare function help it read through all the values and compare them? So it would be based on position $i5 for example. – lemonpole Jul 2 at 21:34 just letting you know I solved the problem by tweaking your sorting function a bit.

I updated my OP with the solution. : thanks for your help. – lemonpole Jul 3 at 23:40.

Usort($standings005, 'cmp') won't work because the first parameter isn't an array to sort, it's just a single number, the points.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions