In PHP, multidimensional array search refers to searching a value in a multilevel nested array. There are various techniques to carry out this type of search, such as iterating over nested arrays, recursive approaches and inbuilt array search functions.
Iterating over the array and searching for significant match is the simplest approach one can follow. 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.
$ --> 1 --> subject
In case, when levels of nested arrays increase, it becomes hard to write such programs and debug them. In such cases its better to write a recursive program which can cleanly be written without adding any nested for loops.
$ --> school3 --> data --> name
Multidimensional array search using array_search() method:
The array_search() is an inbuilt function which searches for a given value related to the given array column/key. This function only returns the key index instead of a search path.
- How to search by key=>value in a multidimensional array in PHP ?
- How to merge the duplicate value in multidimensional array in PHP ?
- Sort a multidimensional array by date element in PHP
- Convert multidimensional array to XML file in PHP
- How to check an array is multidimensional or not in PHP ?
- Multidimensional Associative Array in PHP
- Multidimensional arrays in PHP
- Multidimensional Array in R
- Multidimensional Arrays in Java
- Perl | Multidimensional Hashes
- Perl | Multidimensional Arrays
- How to search by multiple key => value in PHP array ?
- How to search the max value of an attribute in an array object ?
- How to push a value based on matched value in PHP ?
- HTML | DOM Input Search value Property
- Binary Search in PHP
- How to detect search engine bots with PHP ?
- PHP | Print the last value of an array without affecting the pointer
- How to get random value out of an array in PHP?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.