-5

I looked at some questions and answers but didn't find anything. I would like to determine if a number is odd or even. How I can do that?

Example:

odd_or_even(567);

// returns odd
Ivan
  • 34,531
  • 8
  • 55
  • 100

1 Answers1

1

Use modulo:

if ($id % 2 === 0) {
    echo 'even';
} else {
    echo 'odd';
}
YetiCGN
  • 739
  • 4
  • 10