Php Array Element Search Function

What is in_array Function?

Explanation

The "in_array" function can search for array elements if a given value exists

Syntax:


in_array(search,array,type)

In the above syntax "array" is the array in which the elements value specified in "search" has to be looked for. The "type" is an optional field which specifies the type of the search value.

Example :


<?php
$s = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $s))
{
echo "Got Irix";
}
if (in_array("mac", $s))
{
echo "Got mac";
}
?>
Result :

Got Irix

In the above example since the in_array() is case sensitive, displays the result from the first "if" condition.

PHP Topics


Ask Questions

Ask Question