tazo todua tazo todua - 4 months ago 15
PHP Question

pass keyname in array_filter

array_filter
only passes array values, not keynames... how to access keyname?
for example:

$array= array('country'=>'Spain');
array_filter($array,'my_func');


with
my_func
i want to check:


if KEYNAME == 'country' then
...

Answer

array_filter can pass them.

array_filter($array, 'my_func', ARRAY_FILTER_USE_BOTH);

and my_func will then be passed two params; the key, and the value.

array_filter doc page