how to avoid multiples of 10?

Discussion in 'PHP' started by gilgalbiblewheel, Jul 22, 2008.

  1. #1
    I need to express:
    if($i!=){
    PHP:
    $i shouldn't be a multiple of 10.
     
    gilgalbiblewheel, Jul 22, 2008 IP
  2. rob_v

    rob_v Peon

    Messages:
    72
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    if (substr($i,-1))
    {
    echo "Im not a multiple of 10";
    }
    else
    {
    echo "I am";
    }

    Should work - basically testing of a 0 as the last digit - anything else will hit the if - the 0 will hit the else

    let me know fi that works
     
    rob_v, Jul 22, 2008 IP
  3. rob_v

    rob_v Peon

    Messages:
    72
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    or I suppose you can do a mod10 on it also if ($i%10) {not a multiple of 10}else {it is}
     
    rob_v, Jul 22, 2008 IP
  4. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #4
    if($i % 10 != 0){
     
    gilgalbiblewheel, Jul 22, 2008 IP
  5. rob_v

    rob_v Peon

    Messages:
    72
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    That's the thing no need to have to test !=

    If it returns 0 it's false everything else is true.
     
    rob_v, Jul 23, 2008 IP