What could be causing the inconsistent output values in the PHP code provided?

The inconsistent output values in the PHP code could be caused by the use of uninitialized variables or incorrect variable scoping. To solve this issue, make sure all variables are properly initialized before use and pay attention to variable scoping to ensure values are being accessed correctly.

<?php

function calculate_average($numbers) {
    $total = 0; // Initialize total variable
    foreach ($numbers as $num) {
        $total += $num;
    }
    $average = $total / count($numbers);
    return $average;
}

$numbers = [10, 20, 30, 40, 50];
echo calculate_average($numbers);

?>