note 46871 modified in function.array-unique by danbrown
| From: | danbrown@php.net | Date: | Thu, 06 Nov 2008 15:09:02 +0000 |
| Subject: | note 46871 modified in function.array-unique by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-146233@lists.php.net to get a copy of this message | ||
I quite like the following code for making multidimensional arrays unique:
<?php
foreach ($arrAddressList AS $key => $arrAddress) {
$arrAddressList[$key] = serialize($arrAddress);
}
$arrAddressList = array_unique($arrAdressList);
foreach ($arrAddressList AS $key => $strAddress) {
$arrAddressList[$key] = unserialize($strAddress);
}
?>
This gets me a unique array while not minding wether the the original array contains arrays or just
strings (or whatever...).
--was--
I quite like the following code for making multidimensional arrays unique:
foreach ($arrAddressList AS $key => $arrAddress) {
$arrAddressList[$key] = serialize($arrAddress);
}
$arrAddressList = array_unique($arrAdressList);
foreach ($arrAddressList AS $key => $strAddress) {
$arrAddressList[$key] = unserialize($strAddress);
}
This gets me a unique array while not minding wether the the original array contains arrays or just
strings (or whatever...).
http://php.net/manual/en/function.array-unique.php