ArrayList的在PHP [英] ArrayList in php
问题描述
是否有 PHP中的任何数据结构
比阵列
等。是否有可能创建一个数据结构,如的ArrayList
?如果有,请提供一些参考或某种形式实现。
Are there any data structures in php
other than array
. Is it possible to create a data structure such as an ArrayList
? If so please provide some references or some kind of implementation.
推荐答案
您需要了解的一切阵列可以在的 文档 。
Everything you need to know about arrays can be found in the documentation.
所有的数组的可用功能在 函数参考 上市>。
All of the available functions for arrays are listed in the functions reference.
一些注意事项:
- 阵列原本在PHP中唯一的数据结构。这就是为什么他们是如此灵活。他们被认为可用作栈,队列,阵列,列表,哈希表等等。后来PHP推出的 SPL数据结构。
- 与Java,PHP不是一个纯面向对象的语言。数组本身没有内置的可以应用的方法。这已经通过正常的功能来完成。
- 数组有没有固定的大小。他们扩大和自动收缩。
在下面我试着列出PHP替代品最常见的<一个href=\"http://download.oracle.com/javase/1.5.0/docs/api/java/util/ArrayList.html\"><$c$c>ArrayList$c$c>方法的:
In the following I tried to list the PHP alternatives for the most common ArrayList
methods:
-
添加(元素)
基本上是通过追加$数组[] = $元素
。新价值获取下一个免费的数字索引(这是preferred方式)。您也可以使用array_push($数组$元素)
。 -
的addAll(ArrayList的)
:array_merge($数组1,$数组2)
的方式。合并关联数组时要小心。对于相同的密钥值将被覆盖。 -
的clone()
:由于数组是不是对象,你克隆,只需将其分配给另一个变量数组:
add(element)
is basically just appending via$array[] = $element
. The new value gets the next free numeric index (this is the preferred way). You can also usearray_push($array, $element)
.addAll(ArrayList)
:array_merge($array1, $array2)
in a way. Be careful when merging associative arrays. Values for the same keys will be overwritten.clone()
: As arrays are not objects, you "clone" an array by just assigning it to another variable:
$a = array(1,2,3);
$b = $a;
包含(元素)
: in_array($元,$阵列)
这篇关于ArrayList的在PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!