How can you check if a specific email address is present in an array of email addresses in PHP?
To check if a specific email address is present in an array of email addresses in PHP, you can use the in_array() function. This function checks if a value exists in an array and returns true if the value is found, and false otherwise.
<?php
$email = 'example@email.com';
$emailArray = ['test1@email.com', 'test2@email.com', 'example@email.com', 'test3@email.com'];
if (in_array($email, $emailArray)) {
echo "Email address is present in the array.";
} else {
echo "Email address is not present in the array.";
}
?>
Keywords
Related Questions
- What steps can be taken to debug PHP code that is not recognizing a directory as valid when using SSH connection?
- Are there any best practices or specific PHP commands to achieve the desired functionality of reloading only a portion of the webpage?
- What are the potential pitfalls of using functions like fwrite() and fread() in PHP for file operations?