Home >php教程 >php手册 >PHP4新增Array函数简析

PHP4新增Array函数简析

WBOY
WBOYOriginal
2016-06-13 10:25:491088browse

php4的array类函数友多了三个新成员;
分别是:array_unique(), array_intersect() 和 array_diff ()。

顾名思义,这三个函数很简单:

1. array_unique(array array) ------- 将数组中重复的元素去除,然后返回该数组
eg:
$arr = array("a","b","c","b");
$arr = array_unique($arr);
var_dump($arr); ----显示$arr只包含三个元素"a","b","c"

2. array_intersect(array array1,array,array2 .....) ---- 以数组形式返回多个数组中共同拥有的元素
eg:
$arr1 = array("a","b","c","d");
$arr2 = array("e","f","b","a");
$arr = array_unique($arr);
var_dump($arr); ----显示$arr包含两个元素"a","b"

3. array_diff(array array1,array array2) ----- 以数组形式返回array1相较于array2没有的元素。
eg:
$arr1 = array("a","b","c","d");
$arr2 = array("e","f","b","a");
$arr = array_unique($arr);
var_dump($arr); ----显示$arr包含两个元素"c","d" 我感觉php4更人性化了

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