note 77862 added to function.array-unique

From: Date: Sun, 16 Sep 2007 22:39:04 +0000
Subject: note 77862 added to function.array-unique
Groups: php.notes 
Request: Send a blank email to php-notes+get-130543@lists.php.net to get a copy of this message
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)); } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 76.171.101.17 ---- Manual Page -- http://www.php.net/manual/en/function.array-unique.php Edit -- https://master.php.net/note/edit/77862 Del: integrated -- https://master.php.net/note/delete/77862/integrated Del: useless -- https://master.php.net/note/delete/77862/useless Del: bad code -- https://master.php.net/note/delete/77862/bad+code Del: spam -- https://master.php.net/note/delete/77862/spam Del: non-english -- https://master.php.net/note/delete/77862/non-english Del: in docs -- https://master.php.net/note/delete/77862/in+docs Del: other reasons-- https://master.php.net/note/delete/77862 Reject -- https://master.php.net/note/reject/77862 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#130543) next »