note 64553 added to function.array-unique
| From: | nmoyroud at teledetection dot fr | Date: | Tue, 18 Apr 2006 12:56:40 +0000 |
| Subject: | note 64553 added to function.array-unique | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-108408@lists.php.net to get a copy of this message | ||
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;
}
----
Server IP: 194.246.101.61
Probable Submitter: 193.48.189.201
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.array-unique.php
Edit -- http://master.php.net/note/edit/64553
Del: integrated -- http://master.php.net/note/delete/64553/integrated
Del: useless -- http://master.php.net/note/delete/64553/useless
Del: bad code -- http://master.php.net/note/delete/64553/bad+code
Del: spam -- http://master.php.net/note/delete/64553/spam
Del: non-english -- http://master.php.net/note/delete/64553/non-english
Del: in docs -- http://master.php.net/note/delete/64553/in+docs
Del: other reasons-- http://master.php.net/note/delete/64553
Reject -- http://master.php.net/note/reject/64553
Search -- http://master.php.net/manage/user-notes.php