Array ( [0] => 0 [1] => 10 [2] => 20 [3] => 30 [4] => 40 [5] => 50 [6] => 60 [7] => 70 [8] => 80 [9] => 90 [10] => 100 )
Array ( [0] => A [1] => B [2] => C [3] => D [4] => E [5] => F [6] => G [7] => H [8] => I [9] => J [10] => K [11] => L [12] => M [13] => N [14] => O [15] => P [16] => Q [17] => R [18] => S [19] => T [20] => U [21] => V [22] => W [23] => X [24] => Y [25] => Z )
Array ( [0] => z [1] => y [2] => x [3] => w [4] => v [5] => u [6] => t [7] => s [8] => r [9] => q [10] => p [11] => o [12] => n [13] => m [14] => l [15] => k [16] => j [17] => i [18] => h [19] => g [20] => f [21] => e [22] => d [23] => c [24] => b [25] => a )
4.array_fill()函数——填充数组函数:
复制代码 代码如下:
$array = range(1,10);
$fillarray = range("a","d");
$arrayFilled = array_fill(0,5,$fillarray);//这里的$fillarray可以是字符串,如"test".
echo "
"; <br>print_r ($arrayFilled); <br>echo "
";
$keys = array("string","2",9,"SDK","PK");
$array2 = array_fill_keys($keys,"testing");
echo "
"; <br>print_r ($array2); <br>echo "
";
?>
运行结果:
复制代码 代码如下:
Array
(
[0] => Array
(
[0] => a
[1] => b
[2] => c
[3] => d
)
[1] => Array
(
[0] => a
[1] => b
[2] => c
[3] => d
)
[2] => Array
(
[0] => a
[1] => b
[2] => c
[3] => d
)
[3] => Array
(
[0] => a
[1] => b
[2] => c
[3] => d
)
[4] => Array
(
[0] => a
[1] => b
[2] => c
[3] => d
)
)
Array
(
[string] => testing
[2] => testing
[9] => testing
[SDK] => testing
[PK] => testing
)
二、数组的遍历:
1.foreach遍历:
foreach (array_expression as $value){}
foreach (array_expression as $key => $value){}
闲话少说,上实例:
复制代码 代码如下:
$speed = array(50,120,180,240,380);
foreach($speed as $keys=>$values){
echo $keys."=>".$values."
";
}
?>
运行结果:
复制代码 代码如下:
0=>50
1=>120
2=>180
3=>240
4=>380
2.while循环遍历:
while循环遍历一般结合list函数,以下是实例
复制代码 代码如下:
$staff = array(
array("姓名","性别","年龄"),
array("小张","男",24),
array("小王","女",25),
array("小李","男",23)
);
echo "
";
while(list($keys,$value) = each($staff)){
list($name,$sex,$age) = $value;
echo "$name | $sex | $age |
";
}
echo "
";
?>
运行结果:
姓名 |
性别 |
年龄 |
小张 |
男 |
24 |
小王 |
女 |
25 |
小李 |
男 |
23 |
3.for ループのトラバーサル:
コードをコピー コードは次のとおりです:
$speed = range(0,220,20);
for($i =0;$iecho $speed[$i]." "
}
?> 120 140 160 180 200 220
http://www.bkjia.com/PHPjc/323455.htmlwww.bkjia.com
true
http://www.bkjia.com/PHPjc/323455.html
技術記事
今日はPHPデータアプリケーションにおいて最も重要な手法とも言える配列について学びました。 PHP には多くの配列関数があります。以下は私が学んだことをまとめたものです。将来の参考のために覚えておきます。1...
。