bryan_is_south wrote:
> 
> 
> Hello,
> 
> I have a multidimensional array, and would like to sort it by the
> value of the last array.
> 
> Here's the idea of what I've got:
> 
> $Scores[$artist][$album]=$avg;
> 
> So the $Scores array contains an array for each artist, and each
> $artist array contains an array for each album by them. The value for
> the $album array is the average score for the album.
> 
> I want to sort this multidimensional array by the $avg, but I can't
> figure it out.
> 
> Suggestions are much appreciated.
> 
> Thank you in advance
> -bryan

To keep everything intact, you would need to break apart the arrays into 
separate arrays, sort, then put them back together.

Here is an example:
$Scores['smith']['johnsalbum'] = '99';
$Scores['doe']['doesalbum'] = '100';
$Scores['jackson']['jacksonsalbum'] = '96';
$Scores['piper']['pipersalbum'] = '400';

foreach($Scores as $art => $album){
   foreach($album as $alb => $avg){
     $average[$art] = $avg;
     $artist[$art] = $alb;
   }
}
# The next line can be changed to arsort if you want highest avg first.
asort($average);
foreach($average as $k => $v){
   $newscore[$k][$artist[$k]] = $v;
}
print_r($newscore);

Reply via email to