1

My array looks like this:

Array
(
   [1] => Array
      (
         [a] => a
         [b] => b
      )
   [2] => Array
      (
         [a] => c
         [b] => d
      )
   [3] => Array
      (
         [a] => e
         [b] => f
      )
)

And I use this code to search definied value:

$key = array_search('c', array_column($array, 'a'));

But $key not returns '2' (name of key) but '1' (numerically (0, 1, 2, 3)). How I can get name of key?

0

1 Answer 1

1
$key = array_search('c', array_map(function($v){return $v['a'];}, $array));
Sign up to request clarification or add additional context in comments.

1 Comment

Would you mind expanding your answer to explain what's going on here?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.