echo $path; //working
function createList($retval) {
echo $path; //not working
print "<form method='POST' action='' enctype='multipart/form-data'>";
foreach ($retval as $value) {
print "<input type='checkbox' name='deletefiles[]' id='$value' value='$value'>$value<br>";
}
print "<input class='submit' name='deleteBtn' type='submit' value='Datei(en) löschen'>";
print "</form>";
}
what am I doing wrong? why is $path printed correctly outside of the createList function, but it’s not accessible inside the function?
Because it’s not defined in the function.
There are a few ways to go about this:
1) Use what Alex said by telling the function it is a global variable:
2) Define it as a constant:
3) Pass it into the function if it’s specific to that function:
Based on how the function really works, one of those will do ya.