Use in_array function to check if a value exists in an array using PHP
You can use in_array function to check if a value exists in an array:
For example:
<?php
$myname = "David";
$names = array("Paul","Maria","David","Lucy","Ana");
if (in_array($myname, $names))
echo("Welcome $myname");
else
echo "Sorry, that is not a valid name";
?>
Related Articles
- Add an Automatic / Dynamic Copyrighted Year Message in PHP
- Php Mail Function with Html Header
- How to check if an email address exists without sending an email?
- Pass Array from Multipart/Form-data Post Method or Query String with Foreach Function in PHP
- Loop through an Array using Foreach Function in PHP
- Delete File or an Image from the Server using PHP
- Encrypt Decrypt using the Rijndael 256 Mcrypt Function in PHP
- Encrypt Decrypt using the Rijndael 256 Mcrypt Class in PHP
