note 62765 added to function.array-unique
| From: | brettz9 at osu1 dot php dot net | Date: | Thu, 09 Mar 2006 08:51:53 +0000 |
| Subject: | note 62765 added to function.array-unique | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-105113@lists.php.net to get a copy of this message | ||
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
?>
----
Server IP: 61.129.33.155
Probable Submitter: 218.18.63.236
----
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/62765
Del: integrated -- http://master.php.net/note/delete/62765/integrated
Del: useless -- http://master.php.net/note/delete/62765/useless
Del: bad code -- http://master.php.net/note/delete/62765/bad+code
Del: spam -- http://master.php.net/note/delete/62765/spam
Del: non-english -- http://master.php.net/note/delete/62765/non-english
Del: in docs -- http://master.php.net/note/delete/62765/in+docs
Del: other reasons-- http://master.php.net/note/delete/62765
Reject -- http://master.php.net/note/reject/62765
Search -- http://master.php.net/manage/user-notes.php