note 18784 deleted from function.preg-grep by sniper
| From: | sniper@php.net | Date: | Tue, 30 Sep 2003 12:21:39 +0000 |
| Subject: | note 18784 deleted from function.preg-grep by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-57426@lists.php.net to get a copy of this message | ||
Note Submitter: marianna_g@yahoo.com
----
I wrote this little function to match the keys (rather than values) in an associative array to a
pattern. Hope it helps some one.
// function to grep keys of an array for a pattern
// returns an array
function grep_keys($pattern, $array)
{
$newarray = Array();
while( list($key, $val) = each($array))
{
if(preg_match($pattern,$key))
$newarray[$key] = $val;
}
return $newarray;
}