note 105169 deleted from function.array-unique by crell

From: Date: Tue, 12 Apr 2022 00:48:17 +0000
Subject: note 105169 deleted from function.array-unique by crell
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-218162@lists.php.net to get a copy of this message
Note Submitter: Friendly Code ---- I required a function that removed a specific duplicate entry from an array and ignoring all others so came up with this: <?php function specified_array_unique($array, $value) { $count = 0; foreach($array as $array_key => $array_value) { if ( ($count > 0) && ($array_value == $value) ) { unset($array[$array_key]); } if ($array_value == $value) $count++; } return array_filter($array); } ?>

« previous php.notes (#218162) next »