How do i get an odd or even number

This forum covers all minor versions of PHP 7
Post Reply
User avatar
Administrator
Site Admin
Posts: 1725
Joined: Thu Mar 22, 2018 10:19 am

How do i get an odd or even number

Post by Administrator » Fri Aug 24, 2018 10:37 am

You can get the odd and even number by using the modulus operator and comparing with 1 or 0 as shown

Code: Select all

if (($a % 2) == 1)
   /* ODD */
if (($a % 2) == 0)
   /* EVEN */

Post Reply