78 of 110 menu

PHP Odd Number

To check a number for oddness in PHP, simply find the remainder of dividing this number by 2. If this remainder is 0 - the number is even, and if it's 1 - it's odd. The remainder of division can be found using the % operation. See the example:

<?php $num = 3; if ($num % 2 == 0) { echo 'even'; } else { echo 'odd'; } ?>
English
БеларускаяEspañolРусский
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline