1.获取一个数组中重复的元素。代码如下:
a.方法一:
代码如下 | |||||
function array_repeat($arr)
|
b.方法二:
代码如下 | |||||
function array_repeat($arr)
|
测试方法
代码如下 | |||||
$arr = array('apple','blue','red','banana','pear','apple','blue','color','color');
结果: Array ( [5] => apple [6] => blue [8] => color ) |
Later, some methods of deleting duplicate elements from arrays
array_keys function to delete duplicate elements from the array.
*/
The code is as follows | |||||
$a=array("red", "green", "blue", "yellow");
//array array_splice (array input, int offset [, int length [, array replacement]]) |
//下面看一个比较全面的删除重复值并且删除指定的数组元素
代码如下 | |||||
$array1 = array(1 => "www.45it.net", 2 => "菠萝", 4 => "www.45it.net",3 => "香蕉",4 => "芭乐",5 => "www.45it.net",6 => "www.45it.net");
$search_keys = array_keys($array1, "www.45it.net");<🎜> foreach($search_keys as $key) { print_r($array1);<🎜> /* //删除数组中重复元素的函数 |