
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
PHP program to check if the total number of divisors of a number is even or odd
To check if the total number of divisors of a number is even or odd, the code is as follows −
Example
<?php function divisor_count($my_val) { $my_count = 0; for ($i = 1; $i <= sqrt($my_val) + 1; $i++) { if ($my_val % $i == 0) $my_count += ($my_val / $i == $i)? 1 : 2; } if ($my_count % 2 == 0) echo "It is an even number
"; else echo "It is an odd number
"; } divisor_count(100); ?>
Output
It is an odd number
A function named ‘divisor_count’ is defined that gives the number of divisors of a given number that is passed as a parameter to the function. Now, each of these divisors is checked to see if it can be completely divided by 2, if yes, it is an even divisor, and otherwise, it is an odd divisor. Relevant message is displayed on the console.
- Related Articles
- C Program to Check if count of divisors is even or odd?
- Java Program to check if count of divisors is even or odd
- Python Program for Check if the count of divisors is even or odd
- Check if count of divisors is even or odd in Python
- Java Program to Check Whether a Number is Even or Odd
- C++ Program to Check Whether Number is Even or Odd
- How to Check if a Number is Odd or Even using Python?
- 8085 program to check whether the given number is even or odd
- Program to check if a number is Positive, Negative, Odd, Even, Zero?
- C# Program to check if a number is Positive, Negative, Odd, Even, Zero
- Java Menu Driven Program to Check Positive Negative or Odd Even Number
- PHP program to check if a number is prime or not
- How to determine if a number is odd or even in JavaScript?
- Java program to find whether given number is even or odd
- Python Program to Determine Whether a Given Number is Even or Odd Recursively

Advertisements