php数组的创建、调用和更新实现代码_php技巧
时间:2021-07-01 10:21:17
帮助过:45人阅读
代码如下:
$array = array("key1" => "Simon", 2 => "Elaine"); //数组的创建
echo $array["key1"]; //输出Simon
echo $array[2]; //输出Elaine
?>
代码如下:
$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
?>
代码如下:
$array = array("key1" => array(0 => 1, 1 => 10, 2 => 100), //定义数组
"key2" => array(0 => 5, 1 => 25, 2 => 125));
print_r($array); //输出数组
?>
代码如下:
$array = array("a", "b","c"); //定义数组
print_r($array); //输出数组
?>
代码如下:
$array = array("a", "b","c"); //定义数组
$array[0] = "Simon"; //修改数组元素
print_r($array); //输出数组
?>