What are the advantages and disadvantages of using a foreach loop to find the largest value in an array in PHP?

When using a foreach loop to find the largest value in an array in PHP, the advantage is that it is simple and easy to understand. However, the disadvantage is that it may not be the most efficient method, especially for large arrays, as it requires iterating through the entire array.

// Sample array
$array = [4, 8, 2, 10, 6];

// Initialize a variable to store the largest value
$largest = $array[0];

// Loop through the array to find the largest value
foreach ($array as $value) {
    if ($value > $largest) {
        $largest = $value;
    }
}

// Output the largest value
echo "The largest value in the array is: " . $largest;