Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP array_filter, how to get the key in callback?

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?

like image 478
gremo Avatar asked Oct 08 '11 21:10

gremo


1 Answers

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

like image 180
hosseio Avatar answered Sep 22 '22 22:09

hosseio