What is the purpose of storing the value of the pressed button in a variable in PHP?

Storing the value of the pressed button in a variable in PHP allows you to easily access and use the value later in your code. This is particularly useful when dealing with form submissions, as it enables you to perform different actions based on which button was clicked.

<?php
// Check if a specific button was clicked
if(isset($_POST['submit_button'])) {
    $buttonValue = $_POST['submit_button'];
    
    // Perform actions based on the button value
    if($buttonValue == 'Save') {
        // Save data
    } elseif($buttonValue == 'Delete') {
        // Delete data
    }
}
?>

<form method="post">
    <button type="submit" name="submit_button" value="Save">Save</button>
    <button type="submit" name="submit_button" value="Delete">Delete</button>
</form>