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 ?
- Sort a multidimensional array by date element in PHP
- Multidimensional arrays in PHP
- Multidimensional Arrays in Java
- How to search by multiple key => value in PHP array ?
- Binary Search in PHP
- Node | URL.search API
- 2-3 Trees | (Search and Insert)
- Node | urlObject.search API
- Indexed Sequential Search
- HTML | <input type="search">
- Elasticsearch Search Engine | An introduction
- Complexity Analysis of Binary Search
- HTML | DOM Input Search value Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.