Q:

Write a PHP program to check if a given non-negative given number is a multiple of 3 or 7, but not both

0

Write a PHP program to check if a given non-negative given number is a multiple of 3 or 7, but not both

All Answers

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

<?php
function test($n)
{
   return ($n % 3 == 0) ^ ($n % 7 == 0);
 }

var_dump(test(3));
var_dump(test(7));
var_dump(test(21));

Sample Output:

int(1)
int(1)
int(0)

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