Search Value in Multidimensional Array Using PHP
Simple recursive function to search value in multidimensional array in php. Function will return array key(index) with respect to searched value. Just copy paste the function and start using.
If searched values have multiple occurences in array, then it will return first found value key of an array.
function search_in_array($srchvalue, $array) { if (is_array($array) && count($array) > 0) { $foundkey = array_search($srchvalue, $array); if ($foundkey === FALSE) { foreach ($array as $key => $value) { if (is_array($value) && count($value) > 0) { $foundkey = search_in_array($srchvalue, $value); if ($foundkey != FALSE) return $foundkey; } } } else return $foundkey; } }
May this will help you!!!
Thanks for your efforts. You really made my day and saved a lot of time.
Thanks for you feedback
Thanks for your feedback