I noticed there was no way to tell array_unique() to ignore certain duplicated keys, so I wrote the following. I imagine there's half a dozen more efficient ways to do this, but here goes:
<?php
$array = array('foo', 'bar', 'xyzzy', '&', 'xyzzy',
'baz', 'bat', '|', 'xyzzy', 'plugh',
'xyzzy', 'foobar', '|', 'plonk', 'xyzzy',
'apples', '&', 'xyzzy', 'oranges', 'xyzzy',
'pears');
$ignore_values = array('|', '&');
print_r(make_unique($array, $ignore_values));
function make_unique($array, $ignore)
{
while($values = each($array))
{
if(!in_array($values[1], $ignore))
{
$dupes = array_keys($array, $values[1]);
unset($dupes[0]);
foreach($dupes as $rmv)
{
unset($array[$rmv]);
}
}
}
return $array;
}
?>
OUTPUT:
Array
(
[0] => foo
[1] => bar
[2] => xyzzy
[3] => &
[5] => baz
[6] => bat
[7] => |
[9] => plugh
[11] => foobar
[12] => |
[13] => plonk
[15] => apples
[16] => &
[18] => oranges
[20] => pears
)