Jump to content

How can I put a variable name into a string or array


Beauford

Recommended Posts

How can I put a variable name into a string or array?

 

Example:

 

$a = "Uncle Ernie";

$b = "Sally Simpson";

$c = "Tommy";

 

How would I take the actual name of the variable (not the content) and put it in an array like below:

 

$varnames = array(a, b, c);

 

or

 

$varname_a = "a";

$varname_b = "b";

 

I have seen many other similar questions, but no answers. Seems to me like this should be something fairly simple, but as I am finding, the simplest things seem to the hardest.

 

Note: these variable names are going to be from a form - $_POST['a'] etc;

 

Thanks

If you tell us what you are trying to accomplish, someone can directly provide an answer on how to do it.

 

$_POST is already an array. For example, you can use a foreach() loop to iterate over all key/value pairs in it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.