SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there some kind of magical function that detects if a number is even or odd?

    thanx
    Ryan lahay

  2. #2
    SitePoint Zealot jonsteele's Avatar
    Join Date
    Jan 2001
    Location
    Toronto
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    magic

    Use the modulus: %

    In PHP:
    Code:
    $num = 33;
    
    If($num%2)
    {number is odd}
    else{number is even}
    $num%2 returns the remainder when num is devided by two. So you can use it in an if statement. (0 = false, 1 = true)

    Jon.
    Last edited by jonsteele; Apr 26, 2001 at 17:05.

  3. #3
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ah thanx

    I know you could do that in programming ( C++) didnt know there was the same command in php


Bookmarks

Posting Permissions

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