What is the recommended method to convert a variable $password into a SHA256 hash in PHP?

To convert a variable $password into a SHA256 hash in PHP, you can use the hash() function with the algorithm parameter set to 'sha256'. This will securely hash the password for storage or comparison. It is recommended to also use a salt when hashing passwords for added security.

$password = "myPassword123";
$salt = "randomSalt123";
$hashedPassword = hash('sha256', $password . $salt);