What is ucfirst() in PHP?

The ucfirst() function in PHP converts the first character of a string to uppercase.

The figure below shows a visual representation of the ucfirst() function.

Figure 1: Visual representation of ucfirst() function

Syntax

ucfirst(string $string): string

Parameters

The ucfirst() function requires a string whose first character is to be converted to uppercase.

Return value

The ucfirst() function returns the input string, with the first character changed to uppercase and the rest of the string unchanged.

Code

The code below shows how the ucfirst() function works.

<?php
#string
echo("ucfirst('educative'): ");
echo (ucfirst('educative'));
echo("\n");
#string with number
echo("ucfirst('educaTive09'): ");
echo (ucfirst('educaTive09'));
?>