0

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 ...

T.Todua
  • 53,146
  • 19
  • 236
  • 237
  • @Patrick-Q and @ Rizier123 Read the question before marking them as DUPLICATE! In that topic there is no answer for my question! – T.Todua Aug 02 '16 at 18:05
  • Actually, the accepted answer in the linked question is the same solution as what you have accepted here, but actually with a _more precise_ flag passed. So maybe actually read and understand the answers before flying off the handle. – Patrick Q Aug 02 '16 at 18:15
  • @PatrickQ thanks. youa re partially right. i didnt fly of my handle, no worry. just that answer was a bit difficult for me to understand directly. however, before closing the topic, please understand, that if i could get in that answer, i wouldnt had asked here. so, if user asks question, then help him if you can. if not, then at least give hint. look at the accepted answer, that was what i was searching for. – T.Todua Aug 03 '16 at 19:53

1 Answers1

2

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

alzee
  • 1,393
  • 1
  • 10
  • 21