Beauford Posted July 26, 2008 Share Posted July 26, 2008 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 Link to comment https://forums.phpfreaks.com/topic/116778-how-can-i-put-a-variable-name-into-a-string-or-array/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 26, 2008 Share Posted July 26, 2008 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. Link to comment https://forums.phpfreaks.com/topic/116778-how-can-i-put-a-variable-name-into-a-string-or-array/#findComment-600523 Share on other sites More sharing options...
Barand Posted July 26, 2008 Share Posted July 26, 2008 do you mean $varnames = array_keys($_POST); Link to comment https://forums.phpfreaks.com/topic/116778-how-can-i-put-a-variable-name-into-a-string-or-array/#findComment-600526 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.