Write a PHP program to count even number of elements in a given array of integers.
<?php function test($nums) { $evens = 0; for ($i = 0; $i < sizeof($nums); $i++) { if ($nums[$i] % 2 == 0) $evens++; } return $evens; } echo "Number of even elements: ". test([1, 5, 7, 9, 10, 12] );
Sample Output:
Number of even elements: 2
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