How can the use of flush() in PHP code affect the display of progress bars in the browser?
When using flush() in PHP code, it can help to display progress bars in the browser by sending any output that has been buffered to the client immediately. This can be useful when you want to show real-time progress updates to the user. By using flush() in combination with ob_flush(), you can ensure that the progress bar is updated dynamically as the script runs.
ob_start();
for ($i = 0; $i < 10; $i++) {
echo "Progress: " . ($i * 10) . "%<br>";
flush();
ob_flush();
sleep(1); // Simulate some processing time
}
ob_end_flush();