Tuesday, 11 June 2013

How to check if array contains particular value in php

In php we have one function called in_array that can be used to find if the value exists in array

Example with Code and Syntax - 

<?php
$myarr = array("Amol", "Sagar");

if (in_array("Amol",$myarr))
  {
  echo "Amol exists in array";
  }
else
  {
  echo "Amol does not exist in array";
  }
?>

Please remember that if the first parameter is a string and the third parameter is TRUE, searching  is case-sensitive.

This is how we check if particular value exists in an array in php.

No comments:

Post a Comment