How can the PHP documentation on the return function be helpful in resolving issues with loops in arrays?

When working with loops in arrays, it can sometimes be confusing to understand how to properly return values from the loop. This can lead to issues with retrieving the correct data or accessing the desired elements. By referring to the PHP documentation on the return function, you can gain a better understanding of how to structure your loops and use the return statement effectively to retrieve and manipulate array data.

// Example of using the return statement in a loop to return values from an array

$numbers = [1, 2, 3, 4, 5];

function sumArray($arr) {
    $sum = 0;
    foreach($arr as $num) {
        $sum += $num;
    }
    return $sum;
}

echo sumArray($numbers); // Output: 15