I am having trouble getting the value of a variable which is in a function outside the function…
Example:
function myfunction() {
$name = 'myname';
echo $name;
}
Then I call it…
if (something) {
myfunction();
}
This is echoing $name, but if I try to echo $name inside the input value it won’t show:
<input type="text" name="name" value="<?php echo $name ?>"
How can I get access to this variable value?
The
$namevariable is local until you explicitly define it as global:But this doesn’t seem like a good use of globals here. Did you mean to return the value and assign it? (Or just use it once?)