note 21725 deleted from function.array-unique by danbrown
| From: | danbrown@php.net | Date: | Sun, 23 Jan 2011 17:26:14 +0000 |
| Subject: | note 21725 deleted from function.array-unique by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-176203@lists.php.net to get a copy of this message | ||
Note Submitter: bisqwit at iki dot fi
----
array_unique() doesn't return anything useful if your input is an
array containing arrays. This function overcomes the problem.
Any level of recursions is possible here. If the input is a plain
array, the result is compatible with array_unique() result.
<?php
function recursivemakehash($tab)
{
if(!is_array($tab))
return md5($tab);
$p = '';
foreach($tab as $a => $b)
$p .= sprintf('%08X%08X', crc32($a), crc32(recursivemakehash($b)));
return $p;
}
function array_unique2($input)
{
$dumdum = array();
foreach($input as $a => $b)
$dumdum[$a] = recursivemakehash($b);
$newinput = array();
foreach(array_unique($dumdum) as $a => $b)
$newinput[$a] = $input[$a];
return $newinput;
}
?>