note 32051 added to function.array-filter
| From: | skd2 at ece dot msstate dot edu | Date: | Wed, 14 May 2003 20:24:58 +0000 |
| Subject: | note 32051 added to function.array-filter | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-47979@lists.php.net to get a copy of this message | ||
The following function modifies the supplied array recursively so that filtering is performed on
multidimentional arrays as well, while preserving keys.
function array_cleanse(&$arr){
$temp = array();
reset($arr);
if(count($arr) == 0) return "";
foreach($arr as $key=>$val):
(is_array($val))? array_cleanse($val) : NULL;
($val)? $temp[$key] = $val : NULL;
endforeach;
$arr = $temp;
reset($arr);
}
$arr1 =
array('a'=>20,'b'=>array(''),'c'=>array(1,0,2),'d'=>0);
array_cleanse($arr1);
$arr1 will be array('a'=>20,'c'=>array(1,2))
array_filter may not be used as it does not modify the array within itself.
--
http://www.php.net/manual/en/function.array-filter.php
http://master.php.net/manage/user-notes.php?action=edit+32051
http://master.php.net/manage/user-notes.php?action=delete+32051
http://master.php.net/manage/user-notes.php?action=reject+32051