How can the code snippet be optimized to avoid repetitive or redundant operations?

The code snippet can be optimized by storing the result of the repetitive operation in a variable and then using that variable instead of recalculating the same value multiple times. This helps in improving performance by avoiding redundant computations.

// Original code snippet
$length = strlen($text);
if ($length > 10) {
    echo "Text is longer than 10 characters.";
}

// Optimized code snippet
$length = strlen($text);
if ($length > 10) {
    echo "Text is longer than 10 characters.";
}