日期:2012-03-25  浏览次数:20443 次

如题:
$i=[number];
打印如下的图形:

1  2  3  4
12 13 14 5
11 16 15 6
10 9  8  7
  1. /**   
  2.  * 二维数组排序   
  3.  * @param   array $array   
  4.  */    
  5. function sort_recursive(&$array){    
  6.     foreach($array as $key=>$edge){    
  7.         ksort($edge,true);    
  8.         $array[$key]=$edge;    
  9.     }    
  10.     ksort($array,true);    
  11. }    
  12.     
  13. /**   
  14.  * 生成一圈环状数字   
  15.  * @param   array $cotainer    二维数组,包含生成的圈   
  16.  * @param   int $start_value    该圈的起始值   
  17.  * @param   int $x    该圈的偏移值   
  18.  * @param   int $grids_edge    每条边的数字个数   
  19.  */    
  20. function generate(&$container,$start_value,$x,$grids_edge){    
  21.     $rec_times=ceil($grids_edge/2);    
  22.     $center=$grids_edge&1?false:$start_value+4*$rec_times*($rec_times+1);    
  23.     if($center){    
  24.         $index=$x+ceil($grids_edge/2);    
  25.