Q:

Write a PHP program to check if the number of 3's is greater than the number of 5's

0

Write a PHP program to check if the number of 3's is greater than the number of 5's

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?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)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now