Rotating 2-dimensional arrays

Consider the following 2-dimensional array:
[a][b][c][d][e]
[f][g][h][i][j]
[k][l][m][n][o]
[p][q][r][s][t]
I've come up with a PHP function to rotate this array by 90, 180, or 270 degrees.
  1. function rotate($array, $degrees){
  2. if ($degrees != 90 && $degrees != -90 && $degrees != 180) {
  3. return $array;
  4. }
  5.  
  6. $newArray = array();
  7.  
  8. $i = 0;
  9. $arrsize = sizeof($array) - 1;
  10.  
  11. while ($array[0][0]) {
  12. $newArrayRow = array();
  13.  
  14. if ($degrees == 180) {
  15. $row = array_pop($array);
  16.  
  17. while ($row[0]) {
  18. $newArrayRow[] = array_pop($row);
  19. }
  20. $newArray[] = $newArrayRow;
  21. } else {
  22. for ($j = $arrsize; $j >= 0; $j--) {
  23.  
  24. if ($degrees == 90) {
  25. array_push( $newArrayRow, array_shift( $array[$j] ) );
  26. } else {
  27. array_unshift( $newArrayRow, array_shift( $array[$j] ) );
  28. }
  29.  
  30. }
  31. $i++;
  32.  
  33. if ($degrees == 90) {
  34. array_push($newArray, $newArrayRow);
  35. } else {
  36. array_unshift($newArray, $newArrayRow);
  37. }
  38. }
  39. }
  40. return $newArray;
  41. }
The results: rotate($oldArray, 90) returns:
[p][k][f][a]
[q][l][g][b]
[r][m][h][c]
[s][n][i][d]
[t][o][j][e]
rotate($oldArray, -90) returns:
[e][j][o][t]
[d][i][n][s]
[c][h][m][r]
[b][g][l][q]
[a][f][k][p]
rotate($oldArray, 180) returns:
[t][s][r][q][p]
[o][n][m][l][k]
[j][i][h][g][f]
[e][d][c][b][a]
In general, why would you need to rotate a 2-dimensional array?
  1. Image manipulation
  2. Game logic
The second reason in that list is why I need to rotate an array. Stay tuned...