PDA

Click to See Complete Forum and Search --> : [Function] Check if number is a multiple


dclamp
Oct 7th, 2007, 12:47 AM
This function, given a number, multiple, will tell you if it can be divided evenly into it.


function is_multiple($number, $multiple) {
$num = $number / $multiple;
$res = strstr($num, '.');
if ($res == false) {
$return = true;
} else {
$return = false;
}

return $return;
}

//USAGE:

echo is_multiple(25, 5);
//Will print: true

echo is_multiple(6, 5);
//Will print: false

cx323
Oct 7th, 2007, 08:27 PM
I think that can be shortened to something like this:

function is_multiple($number, $multiple)
{
return ($number % $multiple) == 0;
}

dclamp
Oct 7th, 2007, 11:00 PM
yes. i just learned this recently :(