note 77862 deleted from function.array-unique by bjori

From: Date: Mon, 17 Sep 2007 12:58:53 +0000
Subject: note 77862 deleted from function.array-unique by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-130553@lists.php.net to get a copy of this message
Note Submitter: logicearth at gmail dot com Reason: useless ---- Received a request to save the unique items and return those instead. Made two versions one using PHP5 functions the other for PHP4. <?php # array array_unique_save (array array [, bool preserve_keys] ) function array_unique_save ($a, $pk = true) { $a = array_diff_key($a, array_unique($a)); return ($pk ? $a : array_values($a)); } function array_unique_save_php4 ($a, $pk = true) { $r = array(); $a = array_reverse($a, true); foreach ($a as $k => $v) { unset($a[$k]); if (in_array($v, $a)) { $r += array($k => $v); } } $r = array_reverse($r, true); return ($pk ? $r : array_values($r)); } ?>

« previous php.notes (#130553) next »