Can anyone tell me why this works (it echos out “poo”):
$input = "wee";
$val = "poo";
${$input} = $val;
echo $wee;
But this doesn’t:
function bodily($input) {
$val = "poo";
${$input} = $val;
}
bodily("wee");
echo $wee;
I want to use this sort of method to play with some $_POST vars. Please tell me if I can explain more… Cheers!
Your variable
$weegets only defined inside the scope of your functionbodily(). It is not defined outside this function.You could make it
global, anyway this is not a useful pattern for a real life application:outputs