I would like to pass a parameter to a function. However, inside this parameter, I use variables that are defined inside the function.
For example:
<?php
function foo($var){
$test = "test";
echo $var;
}
foo($test);
?>
In this example, I would like for the function to print out “test”. Of course, this returns an error. However, this is what I am trying to do.
You can accomplish this with using
variable-variables, though I don’t understand why you’d want/need to:Notice in the
echostatement insidefoo(), the variable has two$leading. This is avariable-variableand$var‘s value will be treated as a variable-name. So, by callingfoo('test');(the parameter being a string in this case),$$varwill evaluate to$test.