What role does the concept of Salt play in enhancing password security in PHP?

Using a salt in password hashing adds an extra layer of security by adding a random string of characters to the password before hashing it. This makes it more difficult for attackers to crack passwords using techniques like rainbow tables. By using a unique salt for each password, even if two users have the same password, their hashed passwords will be different.

$password = 'password123';
$salt = uniqid(mt_rand(), true); // Generate a unique salt
$hashed_password = hash('sha256', $salt . $password);