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
Go to: http://rosettacode.org/wiki/Spiral_matrix
Here you go:
0);
return $result;
}
function PrintArray($array)
{
for ($i = 0; $i < count($array); $i++) {
for ($j = 0; $j < count($array); $j++) {
echo str_pad($array[$i][$j],3,' ');
}
echo '
';
}
}
$arr = getSpiralArray(4);
echo '';
PrintArray($arr);
echo '
';
?>