php Finding value in array by string and returning another value in the result array? [duplicate]

z9zf31ra  于 2022-12-10  发布在  PHP
关注(0)|答案(1)|浏览(161)

This question already has answers here:

PHP multidimensional array search by value (23 answers)
Closed 3 days ago.
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?

a8jjtwal

a8jjtwal1#

您可以使用array_search函数执行此操作

$key = array_search('Makita', array_column($userdb, 'value'));
echo $userdb[$key]['label'];

相关问题