复制代码 代码如下:
<?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); //输出数组
?>