0

Here is the function to check in multidimensional array.

 public static function inarray($search,$array,$key_=NULL)
{


if(is_array($array))
{

  if(!in_array( $search,$array))
  {
     foreach ($array as $key => $value) {

          Common::inarray($search, $value,$key);
      }   


   }
     else {
        return $key_;
   }
}
else {
     echo FALSE;
}


}

This function not returning any value but it is working.

2
  • What is the problem? Commented Oct 14, 2014 at 11:51
  • not returning any value Commented Oct 14, 2014 at 12:13

1 Answer 1

0

Try this function

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;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.