How can context switching between PHP and HTML affect the output of code?

When context switching between PHP and HTML, it's important to properly close PHP tags when transitioning back to HTML to avoid unexpected output. One common issue is accidentally leaving PHP code open within HTML, which can result in syntax errors or unexpected output. To solve this, make sure to close PHP tags before transitioning to HTML and reopen them when needed.

<?php
// PHP code here

?>

<!DOCTYPE html>
<html>
<head>
    <title>Example</title>
</head>
<body>
    <h1><?php echo "Hello, World!"; ?></h1>
</body>
</html>