How can you differentiate between different form submission buttons in PHP?

When working with form submission buttons in PHP, you can differentiate between different buttons by giving each button a unique name attribute and checking which button was clicked using the $_POST superglobal. This allows you to perform different actions based on which button was clicked.

<form method="post">
    <button type="submit" name="button1">Button 1</button>
    <button type="submit" name="button2">Button 2</button>
</form>

<?php
if(isset($_POST['button1'])) {
    // Code to execute when Button 1 is clicked
} elseif(isset($_POST['button2'])) {
    // Code to execute when Button 2 is clicked
}
?>