note 16802 deleted from function.array-unique by crell

From: Date: Tue, 12 Apr 2022 00:48:02 +0000
Subject: note 16802 deleted from function.array-unique by crell
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-218160@lists.php.net to get a copy of this message
Note Submitter: spunk at dasspunk dot NOSPAM dot com ---- I needed a way of retaining the original array's keys in the new, unique array. I came up with this. It works for my purposes but may need refinement. <?php function my_array_unique($somearray) { asort($somearray); reset($somearray); $currentarrayvar = current($somearray); foreach ($somearray as $key=>$var) { if (next($somearray) != $currentarrayvar) { $uniquearray[$key] = $currentarrayvar; $currentarrayvar = current($somearray); } } reset($uniquearray); return $uniquearray; } ?>

« previous php.notes (#218160) next »