phpvariablesfatal-errorucfirst

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


Solution

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