Home > php教程 > php手册 > php中如何初始化一个数组

php中如何初始化一个数组

WBOY
Release: 2016-06-21 09:07:18
Original
809 people have browsed it

数组

初始化一个数组一般有2种方法:一个是单独给数组中的元素赋值;还有一种是把所有的元素一起初始化。
下面简要介绍初始化数组的2种方法:
第一种方法:
$a["color"]="red";
$a["taste"]="sweet";
$a["shape"]="round";
$a["name"]="apple";
$a[3]=4;
第二种方法:
$a=array(
"color"=>"red",
"taste"=>"sweet",
"shape"=>"round",
"name"=>"apple",
3=>4);

这两种方法的效果是相同的,不同的只是给元素赋值的方法不同。

下面是一个例子,需要注意的是,数组中元素的赋值是从第二个元素开始的。





Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template