What are the best practices for checking if multiple form fields are not simultaneously filled in PHP?

When dealing with multiple form fields in PHP, it's important to ensure that users do not fill in certain fields simultaneously. One way to achieve this is by using conditional statements to check if multiple fields are empty or filled. By implementing this validation logic, you can prevent potential conflicts or errors in the form submission process.

// Check if both fields are not filled simultaneously
if (!empty($_POST['field1']) && !empty($_POST['field2'])) {
    // Handle the error or display a message to the user
    echo "Error: Please only fill in one field at a time.";
} else {
    // Process the form submission
    // Your code to handle form submission goes here
}