note 21725 added to function.array-unique

From: Date: Fri, 24 May 2002 13:36:44 +0000
Subject: note 21725 added to function.array-unique
Groups: php.notes 
Request: Send a blank email to php-notes+get-30979@lists.php.net to get a copy of this message
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. function recursivemakehash($tab) { if(!is_array($tab)) return $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; } -- http://www.php.net/manual/en/function.array-unique.php http://master.php.net/manage/user-notes.php?action=edit+21725 http://master.php.net/manage/user-notes.php?action=delete+21725 http://master.php.net/manage/user-notes.php?action=reject+21725

« previous php.notes (#30979) next »