-1

This is my array:

array(2) {
  [0]=>
  array(2) {
    ["label"]=>
    string(1) "1234"
    ["value"]=>
    string(0) "Bosch"
  }
  [1]=>
  array(2) {
    ["value"]=>
    string(4) "8348"
    ["label"]=>
    string(6) "Makita"
  }
}

Now, I want to search for Makita and get 8348 as a result. How would I do that?

user4095519
  • 271
  • 1
  • 5
  • 12
  • 1
    you will have to do foreach on your array and check if the label matches the string you want to search. If it matches, return value key – Bhavik Dec 06 '22 at 10:17

1 Answers1

1

You can use array_search function for this

$key = array_search('Makita', array_column($userdb, 'value'));
echo $userdb[$key]['label'];
Bhavik
  • 495
  • 2
  • 10