Are there any best practices for handling arithmetic operations in PHP, especially when dealing with user input?

When handling arithmetic operations in PHP, especially with user input, it is important to validate and sanitize the input to prevent potential security vulnerabilities such as SQL injection or code injection attacks. It is also recommended to use appropriate data types and error handling to ensure the calculations are performed accurately and safely.

// Example code snippet for handling arithmetic operations with user input

// Validate and sanitize user input
$number1 = filter_var($_POST['number1'], FILTER_SANITIZE_NUMBER_FLOAT);
$number2 = filter_var($_POST['number2'], FILTER_SANITIZE_NUMBER_FLOAT);

// Perform arithmetic operation
$result = $number1 + $number2;

// Display the result
echo "The result of the operation is: " . $result;