时间:2021-07-01 10:21:17 帮助过:23人阅读
function Circle($n) { $k = $n % 2; $ar = array(); for($i=0; $i<$n; $i++) $ar[$i] = array_fill(0, $n, 0); $p = 1; $x = 0; $y = 0; $m = 0; $len = $n * $n; while($p < $len) { $x = $y = $m; while($x < $n) $ar[$y][$x++] = $p++; $x--; $y++; while($y < $n) $ar[$y++][$x] = $p++; $y--; $x--; while($x >= $m) $ar[$y][$x--] = $p++; $x++; $y--; $m++; while($y >= $m) $ar[$y--][$x] = $p++; $n--; } if($k) $ar[$y+1][$x+1] = $p; $r = '
' . join(' | ', $v) . ' |