Home  >  Article  >  php教程  >  php删除数组中相同的元素,只保留一个相同元素,php数组

php删除数组中相同的元素,只保留一个相同元素,php数组

WBOY
WBOYOriginal
2016-06-13 09:25:101602browse

php删除数组中相同的元素,只保留一个相同元素,php数组

// 删除数组中相同元素,只保留一个相同元素
function formatArray($array)
{
sort($array);
$tem = ”;
$temarray = array();
$j = 0;
for($i=0;$i{
if($array[$i]!=$tem)
{
$temar(www.111cn.net)ray[$j] = $array[$i];
$j++;
}
$tem = $array[$i];
}
return $temarray;
}
//测试 调用函数
$array = array(‘aa’,'bb’,'aa’,3,4,5,5,5,5,’bc’);
$arr = formatArray($array);
print_r($arr);
?>
from:http://www.111cn.net/phper/php/63531.htm

php二维数组删除指定的重复元素,只保留一条

array_unique($array);直接可以移除重复值
 

php删除数组中相同的元素

array_unique($str);
用这个函数,直接删除相同值
 

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