How can PHP arrays be effectively utilized to manage login data?

To manage login data effectively using PHP arrays, you can create an associative array where the keys represent usernames and the values represent passwords. This allows for easy retrieval and verification of login credentials.

// Create an associative array to store login data
$loginData = [
    'username1' => 'password1',
    'username2' => 'password2',
    'username3' => 'password3'
];

// Check if the submitted login credentials are valid
$submittedUsername = $_POST['username'];
$submittedPassword = $_POST['password'];

if(array_key_exists($submittedUsername, $loginData) && $loginData[$submittedUsername] == $submittedPassword) {
    // Login successful
    echo "Login successful!";
} else {
    // Login failed
    echo "Invalid username or password.";
}