php array() 函数
2009-10-23 天天贸易网
Definition and Usage
定义及用法
array() creates an array, with keys and values. If you skip the keys when you specify an array, an integer key is generated, starting at 0 and increases by 1 for each value.
Array()通过键[key]和值[value]创建一个数组。如果你在指定一个数组时不使用“key”键,那它将产生一个整数,其值从“0”开始,每个值递增“1”
Syntax
语法
array(key => value)
Parameter
参数Description
描述
keyOptional. Specifies the key, of type numeric or string. If not set, an integer key is generated, starting at 0
可选参数。指定一个键,可以是数值型或字符型;如果不设置该参数,那么将产生一个整数键,从“0”开始。
valueRequired. Specifies the value
必要参数。指定值。
Example 1
案例1
<?php$a=array("a"=>"Dog","b"=>"Cat","c"=>"Horse");print_r($a);?>
The output of the code above will be:
上述代码将输出以下结果:
Array ( [a] => Dog [b] => Cat [c] => Horse )
Example 2
案例2
<?php$a=array("Dog","Cat","Horse");print_r($a);?>
The output of the code above will be:
上述代码将输出以下结果:
Array ( [0] => Dog [1] => Cat [2] => Horse )