Why is it important to avoid using echo before include in PHP?

Using echo before include in PHP can cause issues because echo outputs content directly to the browser, while include includes a file's content in the current script. If echo is used before include, it can disrupt the file inclusion process and lead to unexpected behavior or errors. To avoid this issue, it is best practice to include files before any output is sent to the browser.

<?php
// Correct way to include a file without using echo before include
include 'header.php';
?>
<!DOCTYPE html>
<html>
<head>
    <title>Page Title</title>
</head>
<body>
    <h1>Hello, World!</h1>
</body>
</html>