How can variables be properly used when setting cookies in PHP?

When setting cookies in PHP, variables can be properly used by concatenating them within the cookie setting function. This allows for dynamic values to be stored in cookies based on the current state of the application or user input.

// Example of setting a cookie with a dynamic variable
$cookie_name = "user";
$cookie_value = "John Doe";
setcookie($cookie_name, $cookie_value, time() + 3600, "/");