Results 1 to 3 of 3

Thread: [Function] Check if number is a multiple

  1. #1

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    [Function] Check if number is a multiple

    This function, given a number, multiple, will tell you if it can be divided evenly into it.

    PHP Code:
    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(255);
    //Will print: [I]true[/I]

    echo is_multiple(65);
    //Will print: [I]false[/I] 
    My usual boring signature: Something

  2. #2
    Lively Member
    Join Date
    Jun 2005
    Posts
    116

    Re: [Function] Check if number is a multiple

    I think that can be shortened to something like this:

    PHP Code:
    function is_multiple($number$multiple)
    {
        return (
    $number $multiple) == 0;


  3. #3

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: [Function] Check if number is a multiple

    yes. i just learned this recently
    My usual boring signature: Something

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width