Q:

Write a PHP program to check if a given array of integers contains a 3 or a 5

0

Write a PHP program to check if a given array of integers contains a 3 or a 5.

All Answers

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

<?php
function test($nums)
 { 

     for ($i = 0; $i < sizeof($nums); $i++)
        {
            if ($nums[$i] != 3 && $nums[$i] != 5) return false;
         }
        return true;
 }   

var_dump(test([5, 5, 5, 5, 5]));
var_dump(test([3, 3, 3, 3]));
var_dump(test([3, 3, 3, 5, 5, 5]));
var_dump(test([1, 6, 8, 10]));

Sample Output:

bool(true)
bool(true)
bool(true)
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