How can multiple functions be used with multiple buttons in PHP?

To use multiple functions with multiple buttons in PHP, you can assign different names to each button and check which button was clicked using conditional statements. Based on the button clicked, you can then call the corresponding function. This allows you to have different actions executed based on the button pressed.

<?php
if(isset($_POST['button1'])){
    // Call function for button 1
    function_for_button1();
}

if(isset($_POST['button2'])){
    // Call function for button 2
    function_for_button2();
}

function function_for_button1(){
    // Function code for button 1
    echo "Button 1 clicked";
}

function function_for_button2(){
    // Function code for button 2
    echo "Button 2 clicked";
}
?>

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