RE: [PHP] delete from array

From: Date: Mon, 10 Mar 2003 18:23:42 +0000
Subject: RE: [PHP] delete from array
Groups: php.general 
Request: Send a blank email to php-general+get-138991@lists.php.net to get a copy of this message
>How do I delete a specific time out of the array or > how do I delete > a range of times out of the array? I would like to be able to delete > 12:05:00 but if I want, delete a range like 12:05:00 to > 12:10:00. Here's some code. Kirk function remove_array_values($valuesToRemove, $array) { if (is_array($array)) { // convert the input to an array, so only one logic block is needed below if (!is_array($valuesToRemove)) { $valuesToRemove = (array) $valuesToRemove; } foreach ($valuesToRemove as $value) { $match = true; // use the do...while to get multiple occurrences of the value to delete do { // array_search returns 'null' or 'false' if the value is not found, // and the index if the value is found, so any number indicates a match $index = array_search($value, $array); if (is_numeric($index)) { unset($array[$index]); } else { $match = false; } } while ($match); } // re-index the array return array_values($array); } else { // return false on bad input return false; } }

« previous php.general (#138991) next »