note 18784 added to function.preg-grep
| From: | marianna_g at yahoo dot com | Date: | Tue, 05 Feb 2002 19:44:09 +0000 |
| Subject: | note 18784 added to function.preg-grep | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-26265@lists.php.net to get a copy of this message | ||
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;
}
--
http://www.php.net/manual/en/function.preg-grep.php
http://master.php.net/manage/user-notes.php?action=edit+18784
http://master.php.net/manage/user-notes.php?action=delete+18784
http://master.php.net/manage/user-notes.php?action=reject+18784