$username = $_POST['username']; $password = $_POST['password']; if ($username == 'myusername' && $password == 'mypassword') { // User authentication successful } else { // User authentication failed }
$number1 = 10; $number2 = "10"; if ($number1 == $number2) { echo "The two numbers are equal"; } else { echo "The two numbers are not equal"; }
$email1 = "john.doe@example.com"; $email2 = "jane.doe@"; if (filter_var($email1, FILTER_VALIDATE_EMAIL)) { echo "The email $email1 is valid"; } else { echo "The email $email1 is not valid"; } if (filter_var($email2, FILTER_VALIDATE_EMAIL)) { echo "The email $email2 is valid"; } else { echo "The email $email2 is not valid"; }In this example, the title equals function is combined with the filter_var function to validate email input. The first email is valid, and the second is not, causing a different output for each. Package library: None, this is a basic PHP function.