note 90101 added to function.array-filter
| From: | Gravis at osu1 dot php dot net | Date: | Mon, 06 Apr 2009 13:53:29 +0000 |
| Subject: | note 90101 added to function.array-filter | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-152861@lists.php.net to get a copy of this message | ||
this actually doesnt use the callback but it's a filter worth mentioning.
removes all empty() elements in an array, even multidimensional ones:
<?php
function array_remove_empty($array)
{
$new_array = array();
foreach($array as $key => $value)
{
if(is_array($value)){$value = array_remove_empty($value);}
if(!empty($value)){$new_array[$key] = $value;}
}
return $new_array;
}
?>
it's inefficient but it's easy to understand and works nonetheless.
----
Server IP: 64.71.164.2
Probable Submitter: 68.230.177.153
----
Manual Page -- http://www.php.net/manual/en/function.array-filter.php
Edit -- https://master.php.net/note/edit/90101
Del: integrated -- https://master.php.net/note/delete/90101/integrated
Del: useless -- https://master.php.net/note/delete/90101/useless
Del: bad code -- https://master.php.net/note/delete/90101/bad+code
Del: spam -- https://master.php.net/note/delete/90101/spam
Del: non-english -- https://master.php.net/note/delete/90101/non-english
Del: in docs -- https://master.php.net/note/delete/90101/in+docs
Del: other reasons-- https://master.php.net/note/delete/90101
Reject -- https://master.php.net/note/reject/90101
Search -- https://master.php.net/manage/user-notes.php