I am trying to create a function that adds data to a PHP session array. I want to dynamically create the Key of the array item as the variable name, and set the value of said key to that variables value. My example code so far:
$foo = 'bar';
addHookpointVar($foo);
function addHookpointVar($var) {
$_SESSION['HOOKPOINT']['foo'] = $var;
}
Is there a method in PHP to get a string representation of a variable, such that my $_SESSION['HOOKPOINT']['VAR'] will be set to the name of the variable passed in?
All the methods I have found involve looping through every variable in the $_GLOBALS