Wednesday, September 24, 2008

How to check if a given value exists in an array using php

If you want to check if a given value exists in a php array variable, you can simply use the php in_array() function. This function will return true if searched value exists else will return false.


<?php

$names = array("Bill", "Kusal", "Rex", "Jhon");

if(in_array("Kusal", $names))
{
echo "Kusal is here";
}
else
{
echo 'Not Found';
}

?>



Get Free Sinhala IT Learning Videos Kuppiya.com

 Subscribe To My Blog

No comments:

Post a Comment