Thoughts and views expressed online by the staff at Aqua Media

Dynamic variable names in PHP

I'm going to show you how to use dynamic variable names in php. It's quite simple, just put your variable name in between {} symbols.

// declare prefix. In a loop this would probably be a number.
$prefix = "pfx";
 
// build your variable
${"varname_{$prefix}"}    = "success";
 
//This would output "success"
echo $varname_pfx;

Simple isn't it....

2 Responses to “Dynamic variable names in PHP”

  1. [...] the original post: Dynamic variable names in PHP | Blogizm SHARETHIS.addEntry({ title: "Dynamic variable names in PHP | Blogizm", url: [...]

  2. [...] See the rest here:  Dynamic variable names in PHP | Blogizm [...]

Powered by Wordpress | A blog by Aqua Media