日期:2014-05-17 浏览次数:20381 次
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 = '<table>'; foreach($ar as $v) $r .= '<tr><td>' . join('</td><td>', $v) . '</td></tr>'; return $r.'</table>'; } for($i=2;$i<30;$i++){ $html .= Circle( $i ); $html .='<hr>'; } ?> <html> <head> <style> ul li { float: left; width: 40px; height: 40px; } hr{clear:both;} </style> </head> <body> <?php echo $html?> </body> </html>