Write a PHP program to check if the number of 3's is greater than the number of 5's
<?php function test($nums) { $no_3 = 0; $no_5 = 0; for ($i = 0; $i < sizeof($nums); $i++) { if ($nums[$i] == 3) $no_3++; if ($nums[$i] == 5) $no_5++; } return $no_3 > $no_5; } var_dump(test([1, 5, 6, 9, 3, 3])); var_dump(test([1, 5, 5, 5, 10, 17])); var_dump(test([1, 3, 3, 5, 5, 5]));
Sample Output:
bool(true) bool(false) 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