Help me create this small if statement.

Discussion in 'PHP' started by Skinny, Feb 23, 2007.

  1. #1
    Okay What I want is to basically detect in a loop each time $1 is a multiple of 5.

    eg. 5, 10, 15, 20

    So i need and if statement the divides $i/5 and can detec if it's an even number.

    Is there a special function in PHP that can do that?

    Skinny
     
    Skinny, Feb 23, 2007 IP
  2. ErectADirectory

    ErectADirectory Guest

    Messages:
    656
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    $i = 0 ;
    $ismultiple5 = 0 ;
    while ($i < $final_amount)
    { // do whatever
    $i ++ ;
    $ismultiple5 ++ ;
    if ($ismultiple5  == 5)
    { // do multiple of 5 stuff then reset $ismultiple5 
    $ismultiple5  = 0 ;
    }
    }
    PHP:
    sounds about right, sorry if my variable naming structure sucks
     
    ErectADirectory, Feb 23, 2007 IP
    Skinny likes this.
  3. Skinny

    Skinny Peon

    Messages:
    1,864
    Likes Received:
    93
    Best Answers:
    0
    Trophy Points:
    0
    #3
    sweet. It makes sense ;)

    I'm gonna try it out. Thanks a lot.

    Skinny
     
    Skinny, Feb 23, 2007 IP
  4. picouli

    picouli Peon

    Messages:
    760
    Likes Received:
    89
    Best Answers:
    0
    Trophy Points:
    0
    #4
    picouli, Feb 23, 2007 IP
    Skinny likes this.
  5. ErectADirectory

    ErectADirectory Guest

    Messages:
    656
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #5
    picouli, your coding is much more elegant than mine & you provide reference. That is how a you are supposed to answer a question.

    Well done, I've jotted down a few notes but cannot guarantee you that I will follow them.
     
    ErectADirectory, Feb 23, 2007 IP
  6. Skinny

    Skinny Peon

    Messages:
    1,864
    Likes Received:
    93
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks to both of you.

    I opted to use picouli's method. though both definitely looked like the were going to work.

    Thanks both. rep added.

    Skinny
     
    Skinny, Feb 23, 2007 IP