note 64553 deleted from function.array-unique by bjori
| From: | bjori@php.net | Date: | Tue, 18 Apr 2006 13:07:14 +0000 |
| Subject: | note 64553 deleted from function.array-unique by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-108410@lists.php.net to get a copy of this message | ||
Note Submitter: nmoyroud at teledetection dot fr
----
I wrote a function to remove all duplicate values from a multi-dimensional array, but in a global
way for the given array.
A lot of functions in the previous contributions do the work only for one column or like
mcmeijer's function for the subarrays at the last level. But what I wanted is a function that
do on an entire multi-dimensional array exactly what do the array_unique function on a single
dimensional one : take an input array and returns a new array without duplicate values.
function arrayUniqueFull($myArray)
{
static $valuesArray = Array();
$newArray = Array();
if (is_array($myArray)) {
foreach($myArray as $key=>$val) {
if (is_array($val)) {
$newArray[$key] = arrayUniqueFull($val);
}
else {
if (!in_array($val, $valuesArray)) {
$newArray[$key] = $val;
$valuesArray[] = $val;
}
}
}
}
return $newArray;
}