How can repetitive code be efficiently outsourced into functions in PHP?

Repetitive code can be efficiently outsourced into functions in PHP by identifying common patterns or tasks that are repeated throughout the code and creating a function to encapsulate that logic. This not only reduces the amount of code duplication but also makes the code more maintainable and easier to update in the future.

// Example of repetitive code being outsourced into a function

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

$rectangle1 = calculateArea(5, 10);
$rectangle2 = calculateArea(8, 12);

echo "Area of rectangle 1: $rectangle1 <br>";
echo "Area of rectangle 2: $rectangle2";