led = array_fill(0,5,$fillarray);//这里的$fillarray可以是字符串,如"test".
echo "<pre>";
print_r ($arrayFilled);
echo "</pre>";
$keys = array("string","2",9,"SDK","PK");
$array2 = array_fill_keys($keys,"testing");
echo "<pre>";
print_r ($array2);
echo "</pre>";
?>
运行结果:
复制代码 代码如下:
Array
(
[0] => Array
(
[0] => a
=> b
=> c
=> d
)
=> Array
(
[0] => a
=> b
=> c
=> d
)
=> Array
(
[0] => a
=> b
=> c
=> d
)
=> Array
(
[0] => a
=> b
=> c
=> d
)
=> Array
(
[0] => a
=> b
=> c
=> d
)
)
Array
(
[string] => testing
=> testing
=> testing
[SDK] => testing
[PK] => testing
)
二、数组的遍历:
1.foreach遍历:
foreach (array_expression as $value){}
foreach (array_expression as $key => $value){}
闲话少说,上实例:
复制代码 代码如下:
<?PHP
$speed = array(50,120,180,240,380);
foreach($speed as $keys=>$values){
echo $keys."=>".$values."<br />";
}
?>
运行结果:
复制代码 代码如下:
0=>50
1=>120
2=>180
3=>240
4=>380
2.while循环遍历:
while循环遍历一般结合list函数,以下是实例
复制代码 代码如下:
<?PHP
$staff = array(
array("姓名","性别","年龄"),
array("小张","男",24),
array("小王","女",25),
array("小李","男",23)
);
echo "<table border=2>";
while(list($keys,$value) = each($staff)){
list($name,$sex,$age) = $value;
echo "<tr><td>$name</td><td>$sex</td><td>$age</td></tr>";
}
echo "</table>";
?>
运行结果:
3.for循环遍历:
复制代码 代码如下:
<?PHP
$speed = range(0,220,20);
for($i =0;$i<count($speed);$i++) {
echo $speed[$i]." ";
}
?>
运行结果:
复制代码 代码如下:
0 20 40 60 80 100 120 140 160 180 200 220