Monday, February 6, 2012

PHP: dynamic variable names

First of all, I want to appologise for not posting to this blog yet... today this is fixed!

So, I just came across a pretty big problem, I needed to take the value from a database field and convert that to a PHP variable so instead of having for example, something that looks like  I needed .

The reason for this is there are some variables that are statically written in a document saying simply, if the database has 1 for then give access, the problem is when it comes out of the database PHP cannot see , it sees that is not the same.

So I did a little Googling and found this article from the PHP Cookbook that gives the options on how to dynamically create a variable.

A great little tip if you come across an application that started exceedingly simple but grew to a size that no longer justifies manually entering variables this way any longer.

Happy coding!

No comments:

Post a Comment