What are the best practices for handling variables with numerical values in PHP?

When handling variables with numerical values in PHP, it is important to ensure that the variables are properly sanitized and validated to prevent any security vulnerabilities or unexpected behavior. It is also recommended to use appropriate data types and functions for numerical operations to ensure accuracy and consistency in calculations.

// Example of handling numerical variables in PHP

// Sanitize and validate input
$number = filter_var($_POST['number'], FILTER_VALIDATE_INT);

// Perform numerical operation
$result = $number * 2;

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