jahsss
jahsss

Reputation: 13

PHP error when using ucfirst() with variables

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

Upvotes: 1

Views: 150

Answers (2)

Athira Das
Athira Das

Reputation: 91

Syntax

ucfirst(string)

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

Upvotes: 1

Sharky
Sharky

Reputation: 409

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']);

Upvotes: 1

Related Questions