In php 5.5.5 & later versions, you can try this

$array_subjected_to_search =array(
array(
        'name' => 'flash',
        'type' => 'hero'
    ),

array(
        'name' => 'zoom',
        'type' => 'villian'
    ),

array(
        'name' => 'snart',
        'type' => 'antihero'
    )
);
$key = array_search('snart', array_column($array_subjected_to_search, 'name'));
var_dump($array_subjected_to_search[$key]);

Output:

array(2) { ["name"]=> string(5) "snart" ["type"]=> string(8) "antihero" }

working sample : http://sandbox.onlinephpfunctions.com/code/19385da11fe0614ef5f84f58b6dae80bd216fc01

Documentation about array_column can be found here

Answer from SRB on Stack Overflow
🌐
Medium
medium.com › @rodgersj097 › how-to-search-a-multi-dimensional-array-in-php-with-internal-functions-2d08a5eb4363
How to search a multi-dimensional array in PHP with internal functions. | by Jacob Rodgers | Medium
October 1, 2020 - array_search(0235, array_column($2dArray, 'Vin')) PHP · Multidimensional · Arrays · 1 follower · ·1 following · Help · Status · About · Careers · Press · Blog · Privacy · Rules ·
🌐
GeeksforGeeks
geeksforgeeks.org › php › php-multidimensional-array-search-by-value
PHP multidimensional array search by value - GeeksforGeeks
July 11, 2025 - Check if an element of the given array is itself an array or not and add the element to the search path, else run array search on the nested array. Example: ... <?php // PHP program to carry out multidimensional array search // Function to ...
🌐
PHP
php.net › manual › en › function.array-search.php
PHP: array_search - Manual
The searched value. ... If needle is a string, the comparison is done in a case-sensitive manner. ... If the third parameter strict is set to true then the array_search() function will search for identical elements in the haystack.
🌐
SitePoint
sitepoint.com › php
Best way to do array_search on multi-dimensional array? - PHP - SitePoint Forums | Web Development & Design Community
May 23, 2012 - Also i doubt you would be able to find an exact code source for what your wanting as retrieving the index for a specific search is faster then storing each key index. ... function array_find_deep($array, $search, $keys = array()) { foreach($array as $key => $value) { if (is_array($value)) { $sub = array_find_deep($value, $search, array_merge($keys, array($key))); if (count($sub)) { return $sub; } } elseif ($value === $search) { return array_merge($keys, array($key)); } } return array(); } $a = array( 'key1' => array( 'key2' => array( 'key3' => 'value', 'key4' => array( 'key5' => 'value2' ) ) )
🌐
Nabilhassen
nabilhassen.com › php-search-multidimensional-array
Searching in a multidimensional array in PHP
October 15, 2025 - array_search() returns the first matching key or false if not found; use the third ($strict) parameter to force === comparison. When you need to search by multiple criteria or across multiple levels, a simple loop gives full control.
🌐
GitHub
gist.github.com › raazon › b39d782e4908b6bf5f359c96ff7b8839
PHP multidimensional array search · GitHub
PHP multidimensional array search. GitHub Gist: instantly share code, notes, and snippets.
🌐
Uptimia
uptimia.com › home › questions › how to search a php multidimensional array by value?
How To Search A PHP Multidimensional Array By Value?
November 5, 2024 - To search a multidimensional array in PHP, you can create a function that loops through the array. This function will compare the 'uid' value of each sub-array with the search parameter.
Find elsewhere
🌐
Experts Exchange
experts-exchange.com › questions › 29076910 › How-to-search-in-this-multidimensional-array-by-using-PHP.html
Solved: How to search in this multidimensional array by using PHP? | Experts Exchange
January 6, 2018 - array_column($arr, 'slug')); $key = array_search('Sons of Anarchy', array_column($arr, 'title')); $record = $arr[$key]; ... I guess something else is necessary... Generates this error: Could you check? ... EARN REWARDS FOR ASKING, ANSWERING, AND MORE. Earn free swag for participating on the platform. ... <?php $jsonstring = '....'; // very long $arr = json_decode($jsonstring, true); $slug = $arr['slug']; $title = $arr['title']; //OK it's printed // print_r($slug); // print_r($title); // Search a film $cont=0; foreach ($arr as $key ) { if ($arr['title'] === 'Suits of Woe') { // How to obtain all the other features of the film....
🌐
TutorialsPoint
tutorialspoint.com › how-to-search-by-key-value-in-a-multidimensional-array-in-php
How to Search by key=value in a Multidimensional Array in PHP
Here's an example of using array_filter() and array_column() to search for a key-value pair in a multidimensional array in PHP:
🌐
Koding Made Simple
kodingmadesimple.com › 2015 › 12 › search-multidimensional-array-for-key-value-php.html
Search Multidimensional Array for Key Value in PHP
This method applies to PHP versions <= 5.4 since there are no built-in functions for performing this sort of array search. We have to do it manually and here is the PHP function to search for the nested array values and return the key from the multidimensional array.
🌐
Javatpoint
javatpoint.com › php-multidimensional-array-search-by-value
PHP Multidimensional Array Search By Value - javatpoint
PHP Multidimensional Array Search By Value with examples, php file, php session, php date, php array, php form, functions, time, xml, ajax, php mysql, regex, string, oop, addslashes(), addcslashes() etc.
🌐
sebhastian
sebhastian.com › php-search-multidimensional-array
PHP how to search multidimensional array with key and value | sebhastian
November 2, 2022 - To handle searching a multidimensional array, you can use either the foreach statement or the array_search() function. A PHP multidimensional array can be searched to see if it has a certain value.
Top answer
1 of 10
235

Another poossible solution is based on the array_search() function. You need to use PHP 5.5.0 or higher.

Example

$userdb=Array
(
    0 => Array
        (
            "uid" => '100',
            "name" => 'Sandra Shush',
            "url" => 'urlof100'
        ),

    1 => Array
        (
            "uid" => '5465',
            "name" => 'Stefanie Mcmohn',
            "pic_square" => 'urlof100'
        ),

    2 => Array
        (
            "uid" => '40489',
            "name" => 'Michael',
            "pic_square" => 'urlof40489'
        )
);

$key = array_search(40489, array_column($userdb, 'uid'));

echo ("The key is: ".$key);
//This will output- The key is: 2

Explanation

The function `array_search()` has two arguments. The first one is the value that you want to search. The second is where the function should search. The function `array_column()` gets the values of the elements which key is `'uid'`.

Summary

So you could use it as:
array_search('breville-one-touch-tea-maker-BTM800XL', array_column($products, 'slug'));

or, if you prefer:

// define function
function array_search_multidim($array, $column, $key){
    return (array_search($key, array_column($array, $column)));
}

// use it
array_search_multidim($products, 'slug', 'breville-one-touch-tea-maker-BTM800XL');

The original example(by xfoxawy) can be found on the DOCS.
The array_column() page.


Update

Due to Vael comment I was curious, so I made a simple test to meassure the performance of the method that uses array_search and the method proposed on the accepted answer.

I created an array which contained 1000 arrays, the structure was like this (all data was randomized):

[
      {
            "_id": "57fe684fb22a07039b3f196c",
            "index": 0,
            "guid": "98dd3515-3f1e-4b89-8bb9-103b0d67e613",
            "isActive": true,
            "balance": "$2,372.04",
            "picture": "http://placehold.it/32x32",
            "age": 21,
            "eyeColor": "blue",
            "name": "Green",
            "company": "MIXERS"
      },...
]

I ran the search test 100 times searching for different values for the name field, and then I calculated the mean time in milliseconds. Here you can see an example.

Results were that the method proposed on this answer needed about 2E-7 to find the value, while the accepted answer method needed about 8E-7.

Like I said before both times are pretty aceptable for an application using an array with this size. If the size grows a lot, let's say 1M elements, then this little difference will be increased too.

Update II

I've added a test for the method based in array_walk_recursive which was mentionend on some of the answers here. The result got is the correct one. And if we focus on the performance, its a bit worse than the others examined on the test. In the test, you can see that is about 10 times slower than the method based on array_search. Again, this isn't a very relevant difference for the most of the applications.

Update III

Thanks to @mickmackusa for spotting several limitations on this method:

  • This method will fail on associative keys.
  • This method will only work on indexed subarrays (starting from 0 and have consecutively ascending keys).

Note on Update III

  • not taking performance into account: you can use array_combine with array_keys & array_column to overcome this limitation in a one-liner like:
$product_search_index = 
array_search( 'breville-one-touch-tea-maker-BTM800XL', array_filter( array_combine( array_keys($products), array_column( $products, 'slug' ) ) ) );
2 of 10
176

Very simple:

function myfunction($products, $field, $value)
{
   foreach($products as $key => $product)
   {
      if ( $product[$field] === $value )
         return $key;
   }
   return false;
}
🌐
W3Schools
w3schools.com › php › func_array_search.asp
PHP array_search() Function
The array_search() function search an array for a value and returns the key. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, ...
🌐
Expertrec
blog.expertrec.com › expertrec custom search engine › others › how to search for a value in a multidimensional array using php - expertrec
How to Search for a Value in a Multidimensional Array using PHP - Expertrec
PHP search value in the multidimensional array can be done by the array_search() which is an in-built function that searches for a particular value associated with the given array column or key.
Published   July 14, 2025
🌐
GitHub
gist.github.com › rseon › 78d6e73b04143b08aaf5147b544499be
[PHP] Search value in multidimensional array · GitHub
[PHP] Search value in multidimensional array. GitHub Gist: instantly share code, notes, and snippets.