Home > php教程 > php手册 > body text

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

WBOY
Release: 2016-06-13 09:25:10
Original
1639 people have browsed it

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);
用这个函数,直接删除相同值
 

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!