note 19249 added to function.array-filter
| From: | sam at php2 dot chek dot com | Date: | Wed, 20 Feb 2002 22:12:48 +0000 |
| Subject: | note 19249 added to function.array-filter | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-26866@lists.php.net to get a copy of this message | ||
Here's a good function to filter multidimensional arrays:
<code>
function array_filter_multi($input, $filter="", $keepMatches=true) {
if (!is_array($input))
return ($input==$filter xor $keepMatches==false) ? $input : false;
while (list ($key,$value) = @each($input)){
$res = array_filter_multi($value, $filter,$keepMatches);
if ($res !== false)
$out[$key] = $res;
}
return $out;
}
</code>
Default behavior is to remove blanks from a multi-dimensional array, but you can filter out any
string (arg #2) with a positive or negative filter (arg #3).
--
http://www.php.net/manual/en/function.array-filter.php
http://master.php.net/manage/user-notes.php?action=edit+19249
http://master.php.net/manage/user-notes.php?action=delete+19249
http://master.php.net/manage/user-notes.php?action=reject+19249