I was wondering if anyone could help me out, I\'m trying to find a script that will check my entire array and remove any duplicates if required, then spit out the array in t
Try this, it works with large arrays:
$original = array('one', 'two', 'three', 'four', 'five', 'two', 'four');
$filtered = array();
foreach ($original as $key => $value){
if(in_array($value, $filtered)){
continue;
}
array_push($filtered, $value);
}
print_r($filtered);
Outputs:
Array
(
[0] => one
[1] => two
[2] => three
[3] => four
[4] => five
)
stop using your own array splitting function that causes duplicates and read the php manual page on array_chunk
My PHP's rusty, but something like this should work:
function makeUniqueBidArray(&$array)
{
$tempArray = array();
foreach($array as $bidArray) {
foreach($bidArray as $bid) {
if (isset($tempArray[$bid->bid]) {
unset($bid);
} else {
$tempArray[$bid->bid] = $bid->name;
}
}
}
}
Use the array_unique function.
Here is an implentation of a multi-dimensional array_unique function.
function super_unique($array)
{
$result = array_map("unserialize", array_unique(array_map("serialize", $array)));
foreach ($result as $key => $value)
{
if ( is_array($value) )
{
$result[$key] = super_unique($value);
}
}
return $result;
}
Not tested, from the comments in the function manual.
You can remove duplicates from an array by doing:
$array = array_values(array_unique($array));