$users = array("John", "Mary", "George", "Anna"); if (in_array("George", $users)) { echo "George is in the array."; } else { echo "George is not in the array."; }
// assuming a connection to a MySQL database has been established $user = "John"; $query = "SELECT * FROM users WHERE username='$user'"; $result = mysqli_query($conn, $query); if (mysqli_num_rows($result) > 0) { echo "User exists in the database."; } else { echo "User does not exist in the database."; }
$users_file = fopen("users.txt", "r"); $user = "Anna"; $found = false; while (!feof($users_file)) { $line = fgets($users_file); if (trim($line) == $user) { $found = true; break; } } if ($found) { echo "User found in the file."; } else { echo "User not found in the file."; }The PHP User Find function is usually part of the PHP standard library, so no additional package library is required.