Home  >  Article  >  Backend Development  >  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
WBOYOriginal
2016-07-13 10:18:391075browse

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...
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