How can the use of sessions in PHP help maintain data between button clicks in a web application?
Sessions in PHP help maintain data between button clicks in a web application by storing data on the server-side and associating it with a unique session ID that is passed between the server and the client. This allows data to persist across multiple page loads and button clicks without the need to constantly pass data through URLs or hidden form fields.
// Start a session
session_start();
// Store data in the session
$_SESSION['username'] = 'JohnDoe';
// Retrieve data from the session
$username = $_SESSION['username'];
// Destroy the session when it's no longer needed
session_destroy();