Matrix arrangement issues in php
I would like to know some solutions to such a problem. It is given a number lets say 16 and you have to arrange a matrix this way 1 2 3 4 12 13 14 5 11 16 15 6 10 9 8 7 the language doesn't matter, (preferably PHP); [EDIT: Update] If language doesn't matter: Go to: http://rosettacode.org/wiki/Spiral_matrix In PHP: Here you go: <?php function getSpiralArray($n) { $pos = 0; $count = $n; $value = -$n; $sum = -1; do { $value = -1 * $value / $n; for ($i = 0; $i < $count; $i++) { $sum += $value; $result[$sum / $n][$sum % $n] = $pos++; } $value *= $n; $count--; for ($i = 0; $i < $count; $i++) { $sum