In PHP, what are the advantages of using password_hash() over manually generating a hash using a private key?

When hashing passwords in PHP, it is recommended to use the password_hash() function instead of manually generating a hash using a private key. This is because password_hash() automatically generates a strong salt and uses a secure hashing algorithm, making it more resistant to attacks such as brute force or rainbow table attacks. Additionally, password_hash() handles the storage and verification of the password hash, simplifying the process for developers.

// Using password_hash() to securely hash a password
$password = "secretPassword";
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);

// Verifying the hashed password
if (password_verify($password, $hashedPassword)) {
    echo "Password is correct!";
} else {
    echo "Password is incorrect!";
}