Function Delsame (& $array)
{
$i = 0;
while (Isset ($array [$i]))
{
$j = $i + 1;
while (Isset ($array [$j]))
{
if ($array [$i] = = $array [$j])//If duplicate elements are found behind
{
Delmember ($array, $j); To remove it
$j--; Re-check to see if the elements that were filled are duplicates
}
$j + +;
}
$i + +;
}
}
function to delete a repeating element in an array
| The code is as follows |
Copy Code |
Function Delmember (& $array, $id)
{
$size = count ($array);
for ($i = 0; $i < $size-$id-1; $i + +)
{
$array [$id + $i] = $array [$id + $i + 1];
}
Unset ($array [$size-1]);
}
|
Use examples:
| The code is as follows |
Copy Code |
$output = Array (1, 2, 2, ' www.111cn.net ', 5, 4, 4, 4, 2, 7, 5, 9, 10);
Delsame ($output);
while (the list ($key, $value) = each ($output))
{
echo "$key: $value". <br> ";
} |
Method Two
| The code is as follows |
Copy Code |
|
function Uniquearray ($array)
{
Get unique ELTs as keys in Assoc. Array
For ($i =0, $n =count ($array, 1); $i < $n; $i)
$u _array[$array [$i]] = 1;
Copy keys to another array
Reset ($u _array, 1);
For ($i =0, $n =count ($u _array, 1); $i < $n; $i) {
$unduplicated _array[] = key ($u _array, 1);
Next ($u _array, 1);
}
return $unduplicated _array;
} |
Method Three
| The code is as follows |
Copy Code |
|
$hills =array ("=>" "Data1", "second" => "" data1/">www.111cn.net", "third" => "data1");
$hills =array_flip ($hills); Restore Key Name
$hills 1=array_flip (Array_flip ($hills));//Delete duplicates
Print_r ($hills 1); |
/*
Array Array_flip (array trans)
Array_flip () returns an inverted array, for example, the key name in trans becomes a value, and the value in trans is the key name.
Note that the value in trans needs to be able to be a valid key name, such as an integer or string. A warning is issued if the type of the value is not correct, and the problematic key/value pair will not be reversed.
If the same value occurs more than once, the last key name is the value, and all the others are lost.
Array_flip () If the failure returns false.
*/