1 $n = 3; 2 $a = []; 3 4 for($i=0;$i<$n*$n;$i++){ 5 6 $a[$i/$n][$i%$n] = 1; 7 } 8 9 echo "<pre>";print_r($a);
运行结果:
Array ( [0] => Array ( [0] => 1 [1] => 1 [2] => 1 ) [1] => Array ( [0] => 1 [1] => 1 [2] => 1 ) [2] => Array ( [0] => 1 [1] => 1 [2] => 1 ) )