How can you optimize the code snippet provided to avoid unnecessary calculations in PHP?

To optimize the code snippet and avoid unnecessary calculations in PHP, we can store the result of the calculation in a variable before checking if it meets the condition. This way, the calculation is only performed once, and the result can be reused as needed.

<?php
$number = 15;
$result = $number * 2;

if ($result > 20) {
    echo "Result is greater than 20";
} else {
    echo "Result is not greater than 20";
}
?>