Tuesday, April 2, 2013

In PHP, how to search a value existed or not in array?

By using in_array function we can knows the element existed or not in that array.

Syntax:

         in_array('search_array_value',$search_array);

Example:

$fruits=array('Apple','Bananna','grapes','Mango');  

In the above array fruits we want to know the array having 'Bananna' value or not!

 if (in_array('Bananna',$fruits))
        {
                   echo 'Fruits having Bananna';
        }
        else
        {
                  echo 'Fruits doesn't having Bananna';
        }

No comments:

Post a Comment