note 96957 deleted from function.array-filter by danbrown

From: Date: Thu, 25 Mar 2010 15:51:31 +0000
Subject: note 96957 deleted from function.array-filter by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-167404@lists.php.net to get a copy of this message
Note Submitter: james [at] bandit.co.nz ---- <?php // array_filter with partial matches, optionally searches keys instead, optionally deletes blank (string) entries // useful for filtering for important $_POST variables function array_filter_partial($needle, $haystack, $filter_keys = false, $delete_blank = false) { if(!is_array($haystack)) return false; $new_arr = array(); foreach($haystack as $key=>$val) { $search = ($filter_keys) ? $key : $val; if($delete_blank && $val=='') continue; else if(strpos($search, $needle)!==false) $new_arr[$key] = $val; } return $new_arr; } ?>

« previous php.notes (#167404) next »