I'm trying to convert a PHP variable to a JS variable using a little helper function that uses variable variables. To simplify, here is what I'm trying to accomplish:
$project_key = 'project 1';
function to_js($variable) {
echo $$variable;
}
to_js('$project_key');
this is supposed simply print
project 1
instead i get
Undefined variable: $project_key
which tells me the variable is being targeted but can't be accessed from the function. How can I access the global var $project_key
from within the function if supplied only with the string $project_key
?