这两种数组赋值方式为什么会有这样的区别

007杀人执照 发布于 2013/03/08 10:42
阅读 176
收藏 1

<?php

$array=array();

for($i=0;$i<10;$i++)

{

    $array[]=$i;

   print_r($array);

   echo '<br>';

}

?>

输出:

Array ( [0] => 0 )
Array ( [0] => 0 [1] => 1 )
Array ( [0] => 0 [1] => 1 [2] => 2 )
Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 )
Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 )
Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 )
Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 [6] => 6 )
Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 [6] => 6 [7] => 7 )
Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 [6] => 6 [7] => 7 [8] => 8 )
Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 [6] => 6 [7] => 7 [8] => 8 [9] => 9 )

 

换一种方式:

$array=array();
for($i=0;$i<10;$i++)
{
 $array=$i;
 print_r($array);
 echo '<br>';
}

 

输出:0
1
2
3
4
5
6
7
8
9
这为什么会有这样的区别,请大神赐教其中的缘由啊!

以下是问题补充:

@007杀人执照:人气怎么这么冷清啊,怎么没人理我了啊? (2013/03/08 11:26)
加载中
0
JavaOlder
JavaOlder
上面是数组。下面是字符~
返回顶部
顶部