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 check an array is multidimensional or not in PHP ?
- Convert multidimensional array to XML file in PHP
- Sort a multidimensional array by date element in PHP
- Multidimensional arrays in PHP
- Multidimensional Arrays in Java
- Perl | Multidimensional Hashes
- Perl | Multidimensional Arrays
- How to search by multiple key => value in PHP array ?
- Difference between Organic Search and Paid Search
- Binary Search in PHP
- Node | URL.search API
- Node | urlObject.search API
- Indexed Sequential Search
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.