Does PHP code retain its variables values when there is HTML code in between?

When there is HTML code in between PHP code, the PHP variables will retain their values as long as the PHP code is within the same script block. However, if the PHP code is separated by HTML code, the variables will not retain their values. To ensure that PHP variables retain their values when there is HTML code in between, you can use PHP echo statements to output the HTML code within the PHP script.

<?php
$variable = "Hello";
echo $variable;
?>
<html>
<body>
<h1><?php echo $variable; ?></h1>
</body>
</html>