How can output being sent before a header modification cause issues in PHP scripts?

Output being sent before a header modification in PHP scripts can cause issues because headers must be sent before any output is sent to the browser. This can lead to errors such as "Headers already sent" or unexpected behavior in the script. To solve this issue, make sure to modify headers before any output is echoed or printed in the script.

<?php
// Correct way to modify headers before any output
header("Content-Type: text/html");

// Rest of the PHP script
echo "Hello, World!";
?>