Skip to content

Latest commit

 

History

History
32 lines (26 loc) · 838 Bytes

0350.md

File metadata and controls

32 lines (26 loc) · 838 Bytes

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(1610462541);
$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