note 68540 added to function.unset

From: Date: Tue, 01 Aug 2006 12:52:04 +0000
Subject: note 68540 added to function.unset
Groups: php.notes 
Request: Send a blank email to php-notes+get-115409@lists.php.net to get a copy of this message
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. ---- Server IP: 203.202.10.60 Probable Submitter: 203.213.7.130 (proxied: 60.240.155.135) ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.unset.php Edit -- https://master.php.net/note/edit/68540 Del: integrated -- https://master.php.net/note/delete/68540/integrated Del: useless -- https://master.php.net/note/delete/68540/useless Del: bad code -- https://master.php.net/note/delete/68540/bad+code Del: spam -- https://master.php.net/note/delete/68540/spam Del: non-english -- https://master.php.net/note/delete/68540/non-english Del: in docs -- https://master.php.net/note/delete/68540/in+docs Del: other reasons-- https://master.php.net/note/delete/68540 Reject -- https://master.php.net/note/reject/68540 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#115409) next »