Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Mar 2005
    Posts
    735
    Thanks
    4
    Thanked 1 Time in 1 Post

    how to avoid multiples of 10?

    I need to express:
    PHP Code:
    if($i!=){ 
    $i shouldn't be a multiple of 10.

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by gilgalbiblewhee View Post
    I need to express:
    PHP Code:
    if($i!=){ 
    $i shouldn't be a multiple of 10.
    PHP Code:
    if($i 10 != 0){ 
    regards

  • #3
    Regular Coder
    Join Date
    Mar 2008
    Posts
    103
    Thanks
    1
    Thanked 8 Times in 8 Posts
    tiny bit more usefull for if you wanna avoid other numbers in the future...

    PHP Code:
    <?php
    function isdiv($number$divby){
          if(
    $number &#37; $divby == 0){
                 
    return true;
          }
          else{
                 return 
    false;
          }
    }
    ?>
    useable for more than one number more than once.....
    Edit:
    To use simple
    $numb = isdiv(10, 2);
    that will set $numb to true.

  • #4
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Quote Originally Posted by p4plus2 View Post
    tiny bit more usefull for if you wanna avoid other numbers in the future...

    I think oesxyl solution is the best. Just replace the 10 with any number and when the remainder = 0 it means that you have reached a multiple of that number. I recommend that the OP study the PHP modulus operator (%), it can be used for all sorts of neat things like alternating row colors, switching banner ads, etc.




    -------------
    Leonard Whistler

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    The actual modulus command has some other uses as well, which is why I would also stick with it.
    PHP has a built in one called fmod for floating notation. I've never used it, but I figure an int typecast would suffice for it. The user notes claim that 1 % 0.2 results in 0.2, but best I remember from computer mathematics that is technically correct for the binary conversion between them. This is the crap that happens when ints are mixed with floats :P
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

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