note 19249 modified in function.array-filter by vrana

From: Date: Tue, 17 Aug 2004 13:58:11 +0000
Subject: note 19249 modified in function.array-filter by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-79925@lists.php.net to get a copy of this message
Here's a good function to filter multidimensional arrays: <?php 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: 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). http://php.net/manual/en/function.array-filter.php

« previous php.notes (#79925) next »