Search code examples
phpvariable-variables

Creating Variable Variables from MySQL Values


Is it possible to create a dynamic variable in PHP based on the value that comes from mysql database?

I mean,

say I have a field in mysql State

When I read the value in php using row['State'] from the database and if I get a value like Alabama, I want to have a variable created like $Alabama_count and I will initialize to 0 or 1.

Thanks.


Solution

  • $varname = $row['State'] . '_count';
    $$varname = 0; // or 1