note 105012 added to function.array-filter
| From: | lisachenko dot it at HUMAN dot gmail dot com | Date: | Fri, 22 Jul 2011 07:54:50 +0000 |
| Subject: | note 105012 added to function.array-filter | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-181774@lists.php.net to get a copy of this message | ||
You can access the current key of array by passing a reference to array into callback function and
call key() and next() method in the callback function:
<?php
$data = array('first' => 1, 'second' => 2, 'third' => 3);
$data = array_filter($data, function ($item) use (&$data) {
echo "Filtering key ", key($data), '<br>', PHP_EOL;
next($data);
return false;
});
?>
However be careful with array internal pointer or use reset() method before calling array_filter().
----
Server IP: 69.147.83.197
Probable Submitter: 213.152.137.45
----
Manual Page -- http://www.php.net/manual/en/function.array-filter.php
Edit -- https://master.php.net/note/edit/105012
Del: integrated -- https://master.php.net/note/delete/105012/integrated
Del: useless -- https://master.php.net/note/delete/105012/useless
Del: bad code -- https://master.php.net/note/delete/105012/bad+code
Del: spam -- https://master.php.net/note/delete/105012/spam
Del: non-english -- https://master.php.net/note/delete/105012/non-english
Del: in docs -- https://master.php.net/note/delete/105012/in+docs
Del: other reasons-- https://master.php.net/note/delete/105012
Reject -- https://master.php.net/note/reject/105012
Search -- https://master.php.net/manage/user-notes.php