What are some best practices for structuring PHP code to handle multiple form actions efficiently?

When handling multiple form actions in PHP, it is best to use a switch statement to determine which action to take based on a submitted form parameter. This allows for efficient and organized code structure, making it easier to maintain and update in the future.

<?php

// Check if form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    
    // Check which form action was submitted
    switch ($_POST['action']) {
        case 'action1':
            // Handle action 1
            break;
        case 'action2':
            // Handle action 2
            break;
        // Add more cases for additional actions
        default:
            // Default action if none match
            break;
    }
}

?>