note 84750 modified in function.array-unique by felipe
| From: | felipe@php.net | Date: | Mon, 28 Jul 2008 22:33:46 +0000 |
| Subject: | note 84750 modified in function.array-unique by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142876@lists.php.net to get a copy of this message | ||
I had a problem with array_unique and multidimensional arrays ... Maybe there's a better way to
do this, but this will work for any dimensional arrays.
<?php
function arrayUnique($myArray)
{
if(!is_array($myArray))
return $myArray;
foreach ($myArray as &$myvalue){
$myvalue=serialize($myvalue);
}
$myArray=array_unique($myArray);
foreach ($myArray as &$myvalue){
$myvalue=unserialize($myvalue);
}
return $myArray;
}
?>
--was--
I had a problem with array_unique and multidimensional arrays ... Maybe there's a better way to
do this, but this will work for any dimensional arrays.
function arrayUnique($myArray)
{
if(!is_array($myArray))
return $myArray;
foreach ($myArray as &$myvalue){
$myvalue=serialize($myvalue);
}
$myArray=array_unique($myArray);
foreach ($myArray as &$myvalue){
$myvalue=unserialize($myvalue);
}
return $myArray;
}
http://php.net/manual/en/function.array-unique.php