note 62765 deleted from function.array-unique by danbrown
| From: | danbrown@php.net | Date: | Sun, 23 Jan 2011 17:24:05 +0000 |
| Subject: | note 62765 deleted from function.array-unique by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-176197@lists.php.net to get a copy of this message | ||
Note Submitter: brettz9
----
If you have a multi-dimensional array and wish to remove duplicates from a particular
"column" as well as the corresponding values in the other "columns", you might
find the following helpful.
<?php
function remove_dups($array, $index) {
$array_count = count($array);
$array_count_inner = count($array[$index]);
for ($i=0; $i<$array_count_inner; $i++) {
for ($j=$i+1; $j<$array_count_inner; $j++) {
if ($array[$index][$i]==$array[$index][$j]) {
for ($k=0; $k<$array_count; $k++) {
unset($array[$k][$i]);
} // end for
} // end if
} // end for
} // end for
return $array;
} // end function remove_dups
?>