Are there best practices for structuring PHP code to avoid header modification errors?

When working with PHP, it's important to ensure that no output is sent to the browser before modifying headers using functions like `header()`. To avoid header modification errors, it's best practice to structure your code so that header modifications are done before any output is sent to the browser. This can be achieved by placing all header modifications at the beginning of the PHP script, before any HTML or text output.

<?php
// Set headers before any output
header('Content-Type: text/html');

// Your PHP code here
echo "Hello, World!";
?>