How can the header() function in PHP be used for redirection?

The header() function in PHP can be used for redirection by sending a raw HTTP header to the browser, instructing it to redirect to a new location. This is commonly used when you want to redirect users to a different page or URL based on certain conditions in your PHP script. Example:

<?php
// Redirect to a new page after 5 seconds
header("refresh:5;url=anotherpage.php");
?>