I have a multidimensional array ($array) in which the entries look like:
{ ["upload/example.gif"]=> array(5) {
["title"]=> string(12) "This is me"
["excerpt"]=> string(24) "This is a photo of a tree"
["img"]=> string(42) "upload/example.gif"
["link"]=> string(23) "http://www.google.co.uk"
["source"]=> string(6) "custom"
}
}
I need to be able to remove any duplicate values in $array based on the key. So if my array was:
$array = array( ["upload/example.gif"] => etc....
["upload/tree.gif"] => etc....
["upload/example.gif"] => etc....)
I would be able to remove one of the ["upload/example.gif"] => etc....
arrays.
I have tried:
$array = array_map('unserialize', array_unique(array_map('serialize', $array)));
but that didn't work.
Thanks in advance.
If a key is not specified for a value, the maximum of the integer indices is taken and the new key will be that value plus 1. If a key that already has an assigned value is specified, that value will be overwritten.
– Treffynnon Apr 11 '11 at 15:03