Natural numbers are the counting numbers. On this page we use the school-friendly rule: an integer is natural when n > 0 (that is, 1, 2, 3, …).
Remember
n is natural ⇔ n is an integer and n > 0
Examples:
1 → natural
42 → natural
0 → not natural (this page)
-3 → not natural
Note: some syllabi include 0. Always state your definition.
n
Check
Result
5
5 > 0
Natural
1
1 > 0
Natural
0
0 > 0 is false
Not natural
-2
-2 > 0 is false
Not natural
Approach
How to Check a Natural 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 1 to N to print natural numbers in a range.
Task
Idea
Time
Best for
Single check
return $n > 0;
O(1)
Yes/no classification
Range print
Loop $i from 1 to N
O(N)
Listing counting numbers
Pseudocode
Pseudocode
function IsNatural(n):
return n > 0
function PrintNaturals(limit):
for i from 1 to limit:
print i
Reference
Cheat Sheet
Keep these facts handy while writing the program.
Topic
Detail
This page rule
$n > 0
Alternate rule
$n >= 0 (includes zero)
Set
{1, 2, 3, …}
Zero
Not natural here — say so in interviews
Negatives
Never natural under either common rule
Helper tip
Return a boolean; let the caller print the message
Try it
Live Preview
Enter any integer to see whether it is natural under n > 0.
Whole numbers only. Tap a chip or type a value.
Result
n = 5
Check: 5 > 0 → true
Verdict: NATURAL 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 → natural
Case B: n = 0
0 > 0 ? no → not natural (on this page)
Case C: n = -3
-3 > 0 ? no → not natural
Code
PHP Programs
Start with a boolean helper for one value. Then print natural numbers from 1 to 10 with a simple loop.
Example 1 — Single Check
Return true when the integer is greater than zero.
php
<?php
function isNatural($n) {
return $n > 0;
}
$number = 5;
if (isNatural($number)) {
echo $number . " is a Natural Number.\n";
} else {
echo $number . " is not a Natural Number.\n";
}
?>
Output
5 is a Natural Number.
How It Works
isNatural encodes the page rule in one comparison: $n > 0.
No loop is needed — the answer is a single boolean.
The caller prints a clear message from that result.
For 5, the check is true, so the program reports a natural number.
Swap in 0 or a negative to see the not-natural branch.
Example 2 — Print Natural Numbers 1 to 10
Natural numbers start at 1, so a forward loop from 1 through 10 lists them.