in_array() PHP Function

By | September 10, 2012

in_array() php function is used to find a variable is present in an array or not.For example: An array has values a,b,c,d and we have to find whether “b” is present in that array. There are two ways

  • Get count from array about total number of values in it, then using for loop we have to find that string is presen tor not.
  • Another easiest way is by using in_array() php function.
Syntax:
in_array(SINGLE VARIABLE, ARRAY):

[code type=php]

<?php
$arr=array(“a”,”b”,”c”,”d”);
$find=”c”;
if(in_array($find,$arr))
{
echo “present”;
}
else
{
echo “Not Present”;
}
?>

[/code]

Leave a Reply

Your email address will not be published. Required fields are marked *

semipurposive-complexional