Checks whether all characters are lowercase letters.
What Is ctype_lower() in PHP?
Checks whether all characters are lowercase letters.
Its syntax is:
ctype_lower(mixed $text): bool
Parameters:
$text— Accepted as mixed; required argument.
Return type: bool. An empty string returns false. These functions examine bytes and locale classification, not full Unicode character properties.
Availability: Requires the ctype extension, normally bundled with PHP.
Example 1: Basic Usage
<?php
var_dump(ctype_lower("hello"));
Output:
bool(true)
An empty string returns false. These functions examine bytes and locale classification, not full Unicode character properties.
Example 2: A Different Input
<?php
var_dump(ctype_lower("Hello"));
Output:
bool(false)
An empty string returns false. These functions examine bytes and locale classification, not full Unicode character properties.
Practical Example: Applying It in a Program
<?php
$samples = ["A1", "AB", "12", "A-1"]; foreach ($samples as $sample) { echo $sample . ": " . (ctype_lower($sample) ? "yes" : "no") . PHP_EOL; }
Output:
A1: no
AB: no
12: no
A-1: no
An empty string returns false. These functions examine bytes and locale classification, not full Unicode character properties.
Important Behavior and Edge Cases
- Key behavior: An empty string returns false. These functions examine bytes and locale classification, not full Unicode character properties.
- Environment: Requires the ctype extension, normally bundled with PHP.
Comparison With Related Functions
| Function | Purpose |
|---|---|
ctype_lower() | Checks whether all characters are lowercase letters. |
preg_match() | preg_match() evaluates a regular-expression pattern; ctype_* functions test every byte against a predefined character class. |
Common Beginner Mistakes
| Mistake | Correct Approach |
|---|---|
| Ignoring this behavior: An empty string returns false | An empty string returns false. These functions examine bytes and locale classification, not full Unicode character properties. |
Key Takeaways
- Checks whether all characters are lowercase letters.
- An empty string returns false. These functions examine bytes and locale classification, not full Unicode character properties.
- Requires the ctype extension, normally bundled with PHP.
Summary: An empty string returns false. These functions examine bytes and locale classification, not full Unicode character properties.