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
这为什么会有这样的区别,请大神赐教其中的缘由啊!

<无标签>
举报

以下是问题补充:

顶部