PHP error when using ucfirst() with variables

121 Views Asked by At

Im trying to display a country name from a database with first letter capitalised. For instance, if the country was Brazil, the database has it as 'brazil', and I would like it to be 'Brazil'.

This is the code I have tried:

ucfirst($name) = $country_aa['name'];

And this is the fatal error returned:

Can't use function return value in write context

Thanks

2

There are 2 best solutions below

0
Sharky On BEST ANSWER

You're not writing to a variable but to a result of a function call. It should be this instead:

$name = ucfirst($country_aa['name']);
0
Athira Das On

Syntax

ucfirst(string)

$country_name = ucfirst($country_aa['name']);