What is the difference between hashing and encryption in PHP, and why is it important to understand this distinction?

Hashing is a one-way function that converts data into a fixed-size string of characters, while encryption is a two-way function that converts data into a scrambled format that can be reversed with a key. It is important to understand this distinction because hashing is commonly used for storing passwords securely, while encryption is used for protecting sensitive data during transmission or storage.

// Hashing example
$password = "secretPassword";
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
echo $hashedPassword;

// Encryption example
$data = "sensitiveData";
$key = "encryptionKey";
$encryptedData = openssl_encrypt($data, "AES-256-CBC", $key);
echo $encryptedData;