Welcome to W3Courses
 Like Us on Facebook

in_array

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";

?>
 

Share