What is the correct syntax for passing a PHP variable in an event handler onclick?

When passing a PHP variable in an event handler onclick, you need to echo the PHP variable within the HTML attribute value. This can be done by enclosing the PHP variable within PHP opening and closing tags within the onclick attribute value. This way, when the HTML is rendered, the PHP variable will be replaced with its value.

<?php
$variable = "Hello World!";
?>

<button onclick="alert('<?php echo $variable; ?>')">Click me</button>