paip.数组以及集合的操作uapi java php python总结..

paip.数组以及集合的操作uapi


作者Attilax  艾龙,  EMAIL:1466519819@qq.com
来源:attilax的专栏
地址:http://blog.csdn.net/attilax


java 以及php ,以及Python数组数据结构对照 
 array(php)>>>>Collection接口(java),arraylist,list,set,map
 1、Python的数组分三种类型:(1) list 普通的链表,初始化后可以通过特定方法动态增加元素。(2) Tuple 固定的数组,一旦定义后,其元素个数是不能再改变的。(2) Dictionary 词典类型, 即是Hash数组。


 
------uapi
Lbound(MyArray) 
Ubound(MyArray) 
Ubound(arrayName)函数
这个函数是返回数组的下标,也就是数组最后一个元素的标记。
1. 合并数组
array_merge()函数将数组合并到一起
2. 追加数组
array_merge_recursive()
3. 连接数组
array_combine()函数会得到一个新数组,它由一组提交的键和对应的值组成。其形式为:
$name = array("apple", "banana", "orange");  
$color = array("red", "yellow", "orange");  
$fruit = array_combine($name, $color);  
  
// Array ( [apple] => red 
[banana] => yellow 
[orange] => orange )  
4. 拆分数组 array_slice()
6. 数组的交集 array_intersect()
 8. 数组的差集 array_diff()
 10. 获取当前数组键 key()
 11. 获取当前数组值 current()
 12. 获取当前数组键和值 each()
  
13. in_array()函数
 
in_array()函数在一个数组汇总搜索一个特定值,如果找到这个值返回true,否则返回false。其形式如下
14. array_key_exists()函数
 
如果在一个数组中找到一个指定的键,函数array_key_exists()返回true,否则返回false。其形式如下:
15. array_search()函数
 
array_search()函数在一个数组中搜索一个指定的值,如果找到则返回相应的键,否则返回false。其形式如下:
 
16. array_keys()函数
 
array_keys()函数返回一个数组,其中包含所搜索数组中找到的所有键。其形式如下:
17. array_values()函数
 
array_values()函数返回一个数组中的所有值,并自动为返回的数组提供数值索引。其形式如下:
18. 在数组头添加元素
 
array_unshift()函数在数组头添加元素
19. 在数组尾添加元素
 
array_push()函数的返回值是int型,
20. 从数组头删除值
 
array_shift()函
21. 从数组尾删除元素
 
array_pop()函
-----------删除数组
array_splice,unset,


------建立数组


1
$fruits[0] = "apple";
然后,可以如下显示数组$fruits的第一个元素:


1
echo $fruits[0] = "apple";
接下来,可以为数组索引映射新值,从而添加其他的值,如下:


1
$fruits[1] = "banana";
2
$fruits[2] = "pear";
有趣的是,如果认为索引值是数组索引而且是递增的,还可以在创建时省略索引值:


1
$fruits[] = "apple";
2
$fruits[] = "banana";
3
$fruits[] = "pear";




、、、、、、、、使用array()创建索引数组的例子:


view sourceprint?
1
$fruits = array("apple","banana","pear");
还可以使用array()创建一个关联数组,如下:


1
$fruits = array(
2
    "AP"=>"apple",
3
    "BA"=>"banana",
4
    "PE"=>"pear"
5
    );
 、、、、、、、、、、、str.split 方法来建立数组.
Collection接口(省略常用的方法)
boolean add(Object obj) 添加一个Object元素
boolean addAll(Collection c)
boolean contains(Object obj)  判断obj是否是调用类集的一个元素(属于)
boolean containsAll(Collection c)  判断c是否是调用类集的子集(包含)
boolean equals(Collection c) 判断c是否与调用类集相等
int hashCode() 返回调用类集的hash码
Iterator iterator() 返回调用类集的迭代程序
boolean removeAll(Collection c) 从调用类集中去掉所有c中包含的元素(差集)
boolean retainAll(Collection c) 从调用类集中去掉包含在c中以外的元素(补集)
Object[] toArray() 返回类集的元素组成的数组
 
void clear()
boolean isEmpty()
int size()




参考
python数组的使用_etaly_新浪博客.htm
探讨如何实现PHP删除数组元素 - 51CTO.COM.htm
php 操作数组 (合并,拆分,追加,查找,删除等) - Just Code - ITeye技术网站.htm
PHP创建数组的方法 -- 简明现代魔法图书馆.htm
很全的php数组操作方法 - Lison - 博客频道 - CSDN.NET.htm
原文地址:https://www.cnblogs.com/attilax/p/15199363.html