数组操作_PHP

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-01 12:39:41902browse

PHP同时支持标量数组(scalar array)和关联数组(associative arrays)。事实上,这两者之间没有任何区别。你可以使用函数list()或array()来创建数组,或者你可以明确的设置每一个数组元素的值。

$a[0] = "abc";

$a[1] = "def";

$b["foo"] = 13;

你也可以通过向数组里添加数值来创建数组。

$a[] = "hello"; // $a[2] == "hello"

$a[] = "world"; // $a[3] == "world"

数组可以通过函数 asort(), arsort(), ksort(), rsort(), sort(), uasort(), usort(), 和ksort() 来进行排序,具体使用那一个函数要根据你所想的排序的类型来定。

你可以使用cunt( )函数来统计数组中元素的个数。

你可以使用next()和prev()函数来遍历数组。另一个普通的遍历数组的方式是使用函数each()。

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
Previous article:数据库支持选项_PHPNext article:其他配制选项_PHP