PHP Remove duplicates from multidimensional array based on key -
i have multidimensional array ($array) in entries like:
{ ["upload/example.gif"]=> array(5) { ["title"]=> string(12) "this me" ["excerpt"]=> string(24) "this photo of tree" ["img"]=> string(42) "upload/example.gif" ["link"]=> string(23) "http://www.google.co.uk" ["source"]=> string(6) "custom" } } i need able remove duplicate values in $array based on key. if array was:
$array = array( ["upload/example.gif"] => etc.... ["upload/tree.gif"] => etc.... ["upload/example.gif"] => etc....) i able remove 1 of ["upload/example.gif"] => etc.... arrays.
i have tried:
$array = array_map('unserialize', array_unique(array_map('serialize', $array))); but didn't work.
thanks in advance.
netcoder answered question properly, wanted show in answer box (instead of comment).
you can't have duplicate keys in associative array (or array). nature of being array can gauranteed have unique keys.
btw if find duplicate data in different keys can remove redundant key unsetting it.
unset($array['delete_me']);
Comments
Post a Comment