PHP merges the same elements in the array, and PHP merges the array elements
This example describes how PHP merges the same elements in an array. Share to everyone for your reference. Specific as follows:
About the deletion of duplicate arrays we have introduced n methods, today This example is a bit different is to delete the same elements in the array, only one of the same elements, the actual instance code is as follows:
Copy the Code code as follows: <?php
Delete the same element in the array, leaving only one of the same elements
function Formatarray ($array)
{
Sort ($array);
$tem = "";
$temarray = Array ();
$j = 0;
for ($i =0; $i<>
{
if ($array [$i]!= $tem)
{
$temarray [$j] = $array [$i];
$j + +;
}
$tem = $array [$i];
}
return $temarray;
}
Test Call function
$array = Array (' AA ', ' BB ', ' AA ', 3,4,5,5,5,5, ' BC ');
$arr = Formatarray ($array);
Print_r ($arr);
?>
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/910595.html www.bkjia.com true http://www.bkjia.com/PHPjc/910595.html techarticle PHP merges the same elements in the array, and PHP merges the elements of the array in this article, which describes the method of PHP merging the same elements in an array. Share to everyone for your reference. Specific as follows: About ...