Q:

Write a PHP program to check if two given non-negative integers have the same last digit

0

Write a PHP program to check if two given non-negative integers have the same last digit.

All Answers

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

<?php
function test($x, $y) 
{
  return abs($x % 10) == abs($y % 10);
}

var_dump(test(123, 456));
var_dump(test(12, 512));
var_dump(test(7, 87));
var_dump(test(12, 45));

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