How can you conditionally set a cookie in PHP based on a specific condition?

To conditionally set a cookie in PHP based on a specific condition, you can use an if statement to check the condition and set the cookie accordingly. This allows you to control when the cookie is set based on certain criteria, such as user input or system variables.

<?php
// Check a specific condition
if ($condition) {
    // Set the cookie with the name 'example' and value 'cookie_value'
    setcookie('example', 'cookie_value', time() + 3600, '/');
}
?>