Home > Backend Development > PHP Tutorial > PHP deletes the same elements in the array and keeps only one identical element, PHP array_PHP tutorial

PHP deletes the same elements in the array and keeps only one identical element, PHP array_PHP tutorial

WBOY
Release: 2016-07-13 10:18:39
Original
1145 people have browsed it

php deletes the same elements in the array and keeps only one same element, php array

// deletes the same elements in the array and keeps only one same element Element
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;
}
//Test calling function
$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 two-dimensional array deletes the specified duplicate elements, leaving only one

array_unique($array); can directly remove duplicate values

php deletes the same elements in the array

array_unique($str);
Use this function to directly delete the same value

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/880676.htmlTechArticlephp deletes the same elements in the array, leaving only one same element, php array?php // Delete the same elements in the array element, only retain one identical element function formatArray($array) { sort($a...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template