Dynamic variable names

from the Artful MySQL Tips List

PHP offers a simple trick for data-driven code, supporting runtime naming of variables: Given ...

$varname = 'firstname'; 

... then prepending an extra dollar sign to the variable name ...

$$varname = 'julie'; 

... creates a variable by that name and assigns the indicated value to it. Then ...

echo $varname, " is ", $$varname, " i.e, ", $firstname; 
firstname is julie i.e, julie

Return to the Artful MySQL Tips page