復制代碼 代碼如下:
<?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); //輸出數組
?>