note 45656 modified in function.array-unique by danbrown
| From: | danbrown@php.net | Date: | Thu, 06 Nov 2008 15:09:18 +0000 |
| Subject: | note 45656 modified in function.array-unique by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-146234@lists.php.net to get a copy of this message | ||
OK, so here's my version that maintains index integrity:
<?php
function array_unique($array)
{
$out = array();
// loop through the inbound
foreach ($array as $key=>$value) {
// if the item isn't in the array
if (!in_array($value, $out)) {
// add it to the array
$out[$key] = $value;
}
}
return $out;
}
?>
--was--
OK, so here's my version that maintains index integrity:
function array_unique($array)
{
$out = array();
// loop through the inbound
foreach ($array as $key=>$value) {
// if the item isn't in the array
if (!in_array($value, $out)) {
// add it to the array
$out[$key] = $value;
}
}
return $out;
}
http://php.net/manual/en/function.array-unique.php