note 68540 deleted from function.unset by bjori

From: Date: Wed, 02 Aug 2006 12:52:56 +0000
Subject: note 68540 deleted from function.unset by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-115450@lists.php.net to get a copy of this message
Note Submitter: gontro at gmail dot com Reason: in docs ---- Ok, so I've been looking around and have yet to find a array_remove or similar function... so I whipped up this. <?php function array_remove($array, $find_value, $amount = null) { $found = 0; foreach ($array as $key => $value) if ($find_value == $value) { unset($array[$key]); $found++; if ($found == $amount) return array_values($array); } return array_values($array); } ?> Basically it takes in the array to be searched, the value to find and the amount of matches to remove (optional, default removes all matches). The returned value is a new, re-sorted array. Hope this is useful to someone.

« previous php.notes (#115450) next »