Home  >  Article  >  php教程  >  数组转成arraylist:PHP array() 数组

数组转成arraylist:PHP array() 数组

WBOY
WBOYOriginal
2016-06-21 08:50:101423browse

array() 创建数组,带有键和值。如果在规定数组时省略了键,则生成一个整数键,这个 key 从 0 开始,然后以 1 进行递增。   要用 array() 创建一个关联数组,可使用 => 来分隔键和值。   
要创建一个空数组,则不传递参数给
array():   
$new = array();
注意:array()
实际上是一种语言结构 (language construct),通常用来定义直接量数组,但它的用法和函数的用法很相似,所以我们把它也列到手册中
PHP array() 例子
array() 声明数组
 

<ol class="dp-c">
<li class="alt"><span><span><?php  </span></span></span></li>
<li><span><span class="vars">$a</span><span>=</span><span class="keyword">array</span><span>(</span><span class="string">"a"</span><span>=></span><span class="string">"Dog"</span><span>,</span><span class="string">"b"</span><span>=></span><span class="string">"Cat"</span><span>,</span><span class="string">"c"</span><span>=></span><span class="string">"Horse"</span><span>); </span></span></li>
<li class="alt"><span>print_r(<span class="vars">$a</span><span>); </span></span></li>
<li><span>?> </span></li>
</ol>


输出:
Array ( [a] => Dog [b] => Cat [c] => Horse )

本文链接http://www.cxybl.com/html/wlbc/Php/20130316/37178.html



Statement:
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