PHP Variable Variables — what?

This is something that ASP does not have. — Variable Variables.

It takes the content of a variable and use it as variable names.

$a = ‘foo’;
$$a = ‘bar’;

the above statement is equivalent to:

$foo = ‘bar’;

Two consecutive $ signs ($$a = ‘bar’) tells PHP to take the value of the variable (in our example, $a which contains ‘foo’) and use that as the variable name, then assign ‘bar’ to that variable.

Why would anyone need to do that? I don’t know. What would be a good real-world example use for this feature? Neat feature, just not sure how useful this would be.

This entry was posted in Uncategorized and tagged , . Bookmark the permalink.