note 19249 modified in function.array-filter by irchtml
| From: | irchtml@php.net | Date: | Wed, 25 Feb 2004 20:18:47 +0000 |
| Subject: | note 19249 modified in function.array-filter by irchtml | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-65755@lists.php.net to get a copy of this message | ||
Here's a good function to filter multidimensional arrays:
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;
}
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).
--was--
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