note 76707 added to function.array-filter
| From: | HayleyWatson at osu1 dot php dot net | Date: | Fri, 27 Jul 2007 02:31:49 +0000 |
| Subject: | note 76707 added to function.array-filter | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-128956@lists.php.net to get a copy of this message | ||
Here is my own version of Renee Sarsoo's array_split() function; given an array and a callback
it returns two arrays, in which the first contains elements that passed the filter and the second
contains elements that didn't. (If no callback is passed, the first array contains the nonempty
elements, as you'd get from array_filter() if you don't give it a callback). Array keys
are preserved.
<?php
function partition($input, $callback=null)
{
static $not_empty=null;
if(is_null($not_empty))
$not_empty = create_function('$o', 'return !empty($o);');
if(is_null($callback)) $callback = $not_empty;
$true = array_filter($input, $callback);
$false = array_diff_key($input, $true);
return array($true, $false);
}
?>
----
Server IP: 202.89.58.1
Probable Submitter: 60.234.168.92
----
Manual Page -- http://www.php.net/manual/en/function.array-filter.php
Edit -- https://master.php.net/note/edit/76707
Del: integrated -- https://master.php.net/note/delete/76707/integrated
Del: useless -- https://master.php.net/note/delete/76707/useless
Del: bad code -- https://master.php.net/note/delete/76707/bad+code
Del: spam -- https://master.php.net/note/delete/76707/spam
Del: non-english -- https://master.php.net/note/delete/76707/non-english
Del: in docs -- https://master.php.net/note/delete/76707/in+docs
Del: other reasons-- https://master.php.net/note/delete/76707
Reject -- https://master.php.net/note/reject/76707
Search -- https://master.php.net/manage/user-notes.php