数组
初始化一个数组一般有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);
这两种方法的效果是相同的,不同的只是给元素赋值的方法不同。
下面是一个例子,需要注意的是,数组中元素的赋值是从第二个元素开始的。
a style="color:#f60; text-decoration:underline;" title= "html"href="https://www.php.cn/zt/15763.html" target="_blank">html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号