What best practices should be followed when structuring PHP code for a project that involves user input and calculations?

When structuring PHP code for a project that involves user input and calculations, it is important to follow best practices to ensure security and maintainability. One key practice is to sanitize and validate user input to prevent SQL injection and other security vulnerabilities. Additionally, separating business logic from presentation logic can make the code easier to maintain and test. Finally, documenting the code and using meaningful variable names can improve readability and understanding.

// Sanitize and validate user input
$input = isset($_POST['input']) ? trim($_POST['input']) : '';
$input = filter_var($input, FILTER_SANITIZE_STRING);

// Separate business logic from presentation logic
function calculate($input) {
    // Perform calculations here
    return $result;
}

// Documenting code and using meaningful variable names
$calculationResult = calculate($input);
echo "The result of the calculation is: " . $calculationResult;