How can the DRY (Don't Repeat Yourself) principle be applied to optimize PHP code?

The DRY principle in PHP can be applied by identifying repetitive code blocks and extracting them into reusable functions or classes. This helps in reducing redundancy, improving code maintainability, and making future updates easier.

// Example of applying DRY principle by creating a reusable function

function calculateArea($length, $width) {
    return $length * $width;
}

$rectangle1 = calculateArea(5, 10);
$rectangle2 = calculateArea(3, 7);