0
<?php
function multi_array_search($search_for, $search_in) {
    foreach ($search_in as $element) {
        if ( ($element === $search_for) || (is_array($element) && multi_array_search($search_for, $element)) ){
            return true;
        }
    }
    return false;
}
$arr = array("2014", array("January", "February", "March"), "2015", array("Monday", "Tuesday"));
echo multi_array_search("Tuesday", $arr) ? 'Found' : 'Not found';
?>

In the above code In multi_array_search("Tuesday",$arr); we are passing first parameter is value and second parameter is an array, But my query is that we are passing first parameter is a set of values.

i.e. we are taking$array=array("2015","Tuesday","March"); Like this and when we found matching values then return 'Found' otherwise return 'Not found' also the value may be case-sensitive,

halfer
  • 18,701
  • 13
  • 79
  • 158
Gopal
  • 43
  • 1
  • 2
  • 6

1 Answers1

0

Converting the the arguments to lowercase by using strtolower() function of PHP makes this job done. The code I come up with is as below, I hope it helps you.

<?php
function multi_array_search($search_for, $search_in) {
$search_for=strtolower($search_for);
foreach ($search_in as $element) {
  if(!is_array($element))
    $element=strtolower($element);
  if ( ($element === $search_for) || (is_array($element) && multi_array_search($search_for, $element)) ){
      return true;
  }
}
return false;
}
$arr = array("2014", array("January", "February", "March"), "2015", array("Monday", "Tuesday"));
echo multi_array_search("TUESDAY", $arr) ? 'Found' : 'Not found';
?>
wupendra
  • 76
  • 8