php 数组的创建、调用和更新实现代码
(编辑:jimmy 日期: 2024/11/19 浏览:3 次 )
复制代码 代码如下:
<?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); //输出数组
?>
<?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); //输出数组
?>
下一篇:在JavaScript中调用php程序