What is output buffering in PHP and how does it relate to the "Cannot modify header information" error?

Output buffering in PHP allows you to store the output of a script in a buffer before sending it to the browser. This can help prevent the "Cannot modify header information" error, which occurs when you try to set a header after content has already been sent to the browser. By using output buffering, you can delay sending any output until after headers have been set, thus avoiding this error.

<?php
ob_start(); // Start output buffering

// Your PHP code here

ob_end_flush(); // Flush the output buffer