A whole number is a counting number plus zero. On this page we use the school-friendly rule: an integer is whole when n >= 0 (that is, 0, 1, 2, 3, …).
Remember
n is whole ⇔ n is an integer and n >= 0
Examples:
0 → whole
1 → whole
42 → whole
-3 → not whole
Natural numbers (this site) use n > 0, so 0 is the only difference.
n
Check
Result
5
5 >= 0
Whole
1
1 >= 0
Whole
0
0 >= 0 is true
Whole
-2
-2 >= 0 is false
Not whole
Approach
How to Check a Whole Number in PHP
Three clear steps — then either classify one value or list a range.
State the definition you will use (here: n >= 0).
Compare the integer against zero and return a boolean.
Optionally loop from 0 to N to print whole numbers in a range.
Task
Idea
Time
Best for
Single check
return n >= 0
O(1)
Yes/no classification
Range print
Loop i from 0 to N
O(N)
Listing whole numbers
Pseudocode
Pseudocode
function IsWhole(n):
return n >= 0
function PrintWholeNumbers(limit):
for i from 0 to limit:
print i
Reference
Cheat Sheet
Keep these facts handy while writing the program.
Topic
Detail
This page rule
n >= 0
Natural rule (this site)
n > 0 (excludes zero)
Set
{0, 1, 2, 3, …}
Zero
Whole — this is what separates whole from natural
Negatives
Never whole
Helper tip
Return a boolean; echo the message at the call site
Try it
Live Preview
Enter any integer to see whether it is a whole number under n >= 0.
Whole numbers only. Tap a chip or type a value.
Result
n = 5
Check: 5 >= 0 → true
Verdict: WHOLE NUMBER
Trace
Worked Walkthrough — n = 5 and n = 0
Apply the same comparison to a yes case and a boundary case.
Calculation
Case A: n = 5
5 >= 0 ? yes → whole
Case B: n = 0
0 >= 0 ? yes → whole (zero is included)
Case C: n = -3
-3 >= 0 ? no → not whole
Code
PHP Programs
Start with a boolean helper for one value. Then print whole numbers from 0 to 10 with a simple for loop.
Example 1 — Single Check
Return true when the integer is zero or greater.
php
<?php
function isWhole($n) {
return $n >= 0;
}
$number = 5;
if (isWhole($number)) {
echo $number . " is a Whole Number.\n";
} else {
echo $number . " is not a Whole Number.\n";
}
?>
Output
5 is a Whole Number.
How It Works
isWhole() encodes the page rule in one comparison: n >= 0.
No loop is needed — the answer is a single boolean.
The call site prints a clear message based on the return value.
For 5, the check is true, so the program reports a whole number.
Swap in 0 to see it is still whole, or a negative to see the not-whole branch.
Example 2 — Print Whole Numbers 0 to 10
Whole numbers start at 0, so a forward loop from 0 through 10 lists them.