How does the echo statement affect the output after using include in PHP?

When using include in PHP, the included file's content is directly outputted to the browser. If the included file contains an echo statement, it will be immediately outputted to the browser as well. To prevent unexpected output, you can store the included file's content in a variable and then echo it where needed.

ob_start();
include 'file.php';
$content = ob_get_clean();

// Now you can use $content as needed without echoing it immediately
echo $content;