note 49177 added to function.preg-match
| From: | kalaxy at nospam dot gmail dot com | Date: | Wed, 19 Jan 2005 03:20:08 +0000 |
| Subject: | note 49177 added to function.preg-match | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-83601@lists.php.net to get a copy of this message | ||
This is another way of implimenting array_preg_match. It also shows use of the array_walk() and
create_function() functions.
<?php
// array_preg_match
// make sure $subject is an array and it will return an array
// of all the elements in $subject that preg_match the
// $pattern.
function array_preg_match($pattern, $subject, $retainkey = false){
$matches = ''; //make sure it's empty
array_walk($subject,
create_function('$val, $key, $array',
'if (preg_match("' . $pattern . '", "$val"))
$array['. ($retainkey ? '$key':'') .'] = $val;'),
&$matches);
return $matches;
}
?>
kalon mills
----
Manual Page -- http://www.php.net/manual/en/function.preg-match.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49177
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49177&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49177&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49177&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49177&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49177&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49177&report=yes
Search -- http://master.php.net/manage/user-notes.php