Q:

Write a PHP program to check a given array of integers and return true if the array contains 10 or 20 twice. The length of the array will be 0, 1, or 2

0

Write a PHP program to check a given array of integers and return true if the array contains 10 or 20 twice. The length of the array will be 0, 1, or 2

All Answers

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

<?php
function test($nums)
 { 
   return sizeof($nums) == 2 && (($nums[0] == 10 && $nums[1] == 10) || ($nums[0] == 20 && $nums[1] == 20));
    
 }   

var_dump(test([12, 20]));
var_dump(test([20, 20]));
var_dump(test([10, 10]));
var_dump(test([10]));

Sample Output:

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