How can the placement of session_start() affect the occurrence of the "headers already sent" error in PHP?

When session_start() is called after any output has been sent to the browser, it can lead to the "headers already sent" error in PHP. To solve this issue, session_start() should be placed at the very beginning of the PHP script, before any HTML, whitespace, or other output is sent to the browser.

<?php
session_start();

// Rest of the PHP code goes here
?>