12345678_0001
2019-06-07 11:06:48
我是PHP的新手。我看到網(wǎng)上說(shuō)使用while循環(huán)寫入數(shù)組更快一點(diǎn),請(qǐng)問(wèn),如何使用while循環(huán)寫入數(shù)組數(shù)據(jù)?請(qǐng)?jiān)敿?xì)描述一下并舉出幾個(gè)例子。謝謝
2 回答

阿波羅的戰(zhàn)車
TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超6個(gè)贊
循環(huán)寫入示例如下(其他循環(huán)寫入原理也是一樣的):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | <?php
//定義空數(shù)組 $arr= array(); //循環(huán)初始化條件 $i=1; //根據(jù)判斷進(jìn)行while循環(huán) while($i<=10){ //寫入數(shù)組 $arr[]="元素".$i; //遞增 $i++; } print_r($arr);
/* * Array ( [0] => 元素1 [1] => 元素2 [2] => 元素3 [3] => 元素4 [4] => 元素5 [5] => 元素6 [6] => 元素7 [7] => 元素8 [8] => 元素9 [9] => 元素10 )*/ ?> |
- 2 回答
- 0 關(guān)注
- 977 瀏覽
添加回答
舉報(bào)
0/150
提交
取消