PHP lcfirst() Function

Quick summary: The PHP lcfirst() function makes the first character of a string lowercase.

PHP lcfirst() Syntax

lcfirst(string $string): string
PHP

PHP lcfirst() Basic examples

echo lcfirst("HelloWorld");
PHP
Output:
helloWorld

Lowercases the first character of a string.

PHP lcfirst() Real-world usage

$method = "GetUser";
echo lcfirst($method);
PHP
Output:
getUser

Converts method names to camelCase.

PHP lcfirst() Edge cases

echo lcfirst("1Test");
PHP
Output:
1Test

If the first character is not a letter, nothing changes.

PHP lcfirst() Common mistakes

Using lcfirst for full lowercase conversion

lcfirst affects only the first character.

Incorrect
echo lcfirst("HELLO");
Correct
echo strtolower("HELLO");

Use strtolower() to convert the entire string.

PHP lcfirst() Frequently Asked Questions

What does lcfirst() do in PHP?

lcfirst() converts the first character of a string to lowercase.

Does lcfirst() affect the rest of the string?

No, lcfirst() only changes the first character and leaves the rest unchanged.

Is lcfirst() multibyte-safe?

No, lcfirst() is not multibyte-safe. Use mb_convert_case() for UTF-8 strings.

Does lcfirst() modify the original string?

No, lcfirst() returns a new string and does not modify the original variable unless reassigned.

What happens if the string starts with a non-letter?

lcfirst() will not change the string if the first character is not alphabetic.

What is the difference between lcfirst() and strtolower()?

lcfirst() lowercases only the first character, while strtolower() converts the entire string to lowercase.

Does lcfirst() work with Unicode characters?

No, lcfirst() may not handle Unicode correctly. Use multibyte-safe alternatives.

Can lcfirst() be used for formatting variables?

Yes, lcfirst() is often used to format variable or method names in camelCase.

What happens if the string is empty?

lcfirst() returns an empty string if the input string is empty.

Is lcfirst() case-sensitive?

lcfirst() only affects the first character and does not change the rest of the string.

Can lcfirst() handle arrays?

No, lcfirst() works only with strings. Use array_map() for arrays.

What is a real-world use case of lcfirst()?

lcfirst() is commonly used for formatting strings into camelCase or normalizing identifiers.

PHP lcfirst() Related PHP Functions