Tuesday, September 15, 2009

PHP in_array() Function

in_array() is used to search for an array element through the array. It is the standard of  PHP4.
The basic construction of in_array ( ) is

in_array(element,array,type);

Here:
element, is the element to be searched.(Required Parameter)
array, is the given array in which we will make our search.(Required Parameter)
type, If this parameter is set, the in_array() function searches for the search-string and specific type in the array (Optional parameter).

Example:

  $fruit = array("apple", "mango", "orange");

if (in_array("apple",$fruit))
  {
  echo "Match found";
  }
else
  {
  echo "Match not found";
  }
?>

OUTPUT:
Match found









munir  hoque  in_array  php 

1 comment:

  1. Nice post, but I think, It will better if you explain more abt the 'type' parameter of in_array().

    ReplyDelete