php 数组的创建、调用和更新实现代码

2015-01-24信息快讯网

对于php的数组是php中很重要的一个地方,大家一定要仔细看。

<?php 
$array = array("key1" => "Simon", 2 => "Elaine"); //数组的创建 
echo $array["key1"]; //输出Simon 
echo $array[2]; //输出Elaine 
?>


<?php 
$array = array("key1" => array(0 => 1, 1 => 10, 2 => 100), 
"key2" => array(0 => 5, 1 => 25, 2 => 125)); 
echo $array["key1"][0]; //输出1 
echo $array["key1"][1]; //输出10 
echo $array["key1"][2]; //输出100 
echo $array["key2"][0]; //输出5 
echo $array["key2"][1]; //输出25 
echo $array["key2"][2]; //输出125 
?>


<?php 
$array = array("key1" => array(0 => 1, 1 => 10, 2 => 100), //定义数组 
"key2" => array(0 => 5, 1 => 25, 2 => 125)); 
print_r($array); //输出数组 
?>


<?php 
$array = array("a", "b","c"); //定义数组 
print_r($array); //输出数组 
?>


<?php 
$array = array("a", "b","c"); //定义数组 
$array[0] = "Simon"; //修改数组元素 
print_r($array); //输出数组 
?>
©2014-2024 dbsqp.com