Write a PHP program to check if the sum of all 5' in the array exactly 15 in a given array of integers
<?php function test($nums) { $sum = 0; for ($i = 0; $i < sizeof($nums); $i++) { if ($nums[$i] == 5) $sum += 5; } return $sum == 15; } var_dump(test([1, 5, 6, 9, 10, 17])); var_dump(test([1, 5, 5, 5, 10, 17])); var_dump(test([1, 1, 5, 5, 5, 5]));
Sample Output:
bool(false) bool(true) bool(false)
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer