How can the PHP code provided be optimized for better performance and readability?

The PHP code can be optimized for better performance and readability by reducing unnecessary repetition and improving code organization. One way to achieve this is by using functions to encapsulate repetitive logic and improve code maintainability. Additionally, using meaningful variable names and comments can enhance readability.

// Optimized PHP code for better performance and readability

// Function to calculate the sum of an array
function calculateSum($array) {
    $sum = 0;
    foreach ($array as $value) {
        $sum += $value;
    }
    return $sum;
}

// Input array
$array = [1, 2, 3, 4, 5];

// Calculate sum of the array
$sum = calculateSum($array);

echo "The sum of the array is: " . $sum;