What is the simplest most basic way to find out if a number/variable is odd or even in PHP?
Is it something to do with mod?
I’ve tried a few scripts but.. google isn’t delivering at the moment.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You were right in thinking mod was a good place to start. Here is an expression which will return true if
$numberis even, false if odd:Works for every integerPHP value, see as well Arithmetic OperatorsPHP.
Example:
Output: