How does the use of header() function in PHP scripts impact the output and execution flow of the code?

Using the header() function in PHP scripts allows you to send raw HTTP headers to the browser, which can be used for various purposes such as redirecting the user to a different page, setting cookies, or specifying the content type. It's important to note that the header() function must be called before any actual output is sent to the browser, as headers must be sent before any content. Failure to do so may result in errors or unexpected behavior.

<?php
// Set a HTTP header to redirect the user to a different page
header("Location: https://www.example.com");
exit; // Make sure to exit after setting the header to prevent further code execution
?>