note 33517 added to function.array-filter

From: Date: Sat, 28 Jun 2003 17:01:33 +0000
Subject: note 33517 added to function.array-filter
Groups: php.notes 
Request: Send a blank email to php-notes+get-51136@lists.php.net to get a copy of this message
Hi all, Here's a function that will look trough an array, and removes the array member when the search string is found. function array_clean ($input, $delete = false, $caseSensitive = false) { $i = 0; while($i < count($input)) { if($delete) { if($caseSensitive) { if(!strstr($input[$i] ,$delete)) { $return[] = $input[$i]; } } else { if(!stristr($input[$i], $delete)) { $return[] = $input[$i]; } } } else { if(!empty($input[$i])) { $return[] = $input[$i]; } } $i++; } return $return; } array array_clean(array input [, string needle [, boolean case sensitive]]) if needle is left empty, the function will delete the array members that have no value (this means if it's empty). NOTE: It rebuilds the array from scratch, so keys begin with 0, like you would create a new array. Example: $array = array("John", "Doe", "Macy"); $array = array_clean($array, "doe", false); print_r($array); would return: array ( [0] => John [1] => Macy ) Hopes this helps someone :-) ---- Manual Page -- http://www.php.net/manual/en/function.array-filter.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33517 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33517&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33517&report=yes

« previous php.notes (#51136) next »