<<< Previous question <<< Question ID#0350.md >>> Next question >>>
The following script is supposed to determine the largest value in an array, however, it may not work correctly. Examine the script and recommend changes if required.
$ages = array(16, 10, 46, 25, 41);
$largest = -1;
foreach ($ages as $age) {
if ($largest < 0) {
$largest = $age;
break;
}
if ($age > $largest) {
$largest = $age;
}
}
echo sprintf('The largest age is %d', $largest);
- A) Change "break" to "continue"
- B) The comparison between $age and $largest is backwards
- C) Change the sprintf() call to output $age
- D) No changes required
Answer
Answer: A