note 49177 deleted from function.preg-match by colder
| From: | colder@php.net | Date: | Mon, 18 Jun 2007 18:18:16 +0000 |
| Subject: | note 49177 deleted from function.preg-match by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-127588@lists.php.net to get a copy of this message | ||
Note Submitter: kalaxy at nospam dot gmail dot com
----
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