PHP array_filter, how to get the key in callback?

gremo picture gremo · Oct 8, 2011 · Viewed 16.2k times · Source

array_filter — Filters elements of an array using a callback function

array array_filter ( array $input [, callback $callback ] )

Can callback get the key of the current array value and how?

Answer

hosseio picture hosseio · Feb 3, 2015

From the documentation: PHP 5.6.0 Added optional flag parameter and constants ARRAY_FILTER_USE_KEY and ARRAY_FILTER_USE_BOTH

http://php.net/manual/en/function.array-filter.php