取消设置 PHP 脚本中的所有变量
2022-08-31 00:52:36
尝试自动取消设置脚本中的所有变量。
尝试过这种方式:
echo '<br /> Variables in Script before unset(): <br />';
print_r(array_keys(get_defined_vars()));
echo '<br /><br />';
var_dump(get_defined_vars());
// Creates string of comma-separated variables(*) for unset.
$all_vars = implode(', $', array_keys(get_defined_vars()));
echo '<br /><br />';
echo '<br />List Variables in Script: <br />';
echo $all_vars;
unset($all_vars);
echo '<br /><br />';
echo '<br />Variables in Script after unset(): <br />';
print_r(array_keys(get_defined_vars()));
echo '<br />';
var_dump(get_defined_vars());
为什么它不起作用?
有没有更好的方法来做到这一点?
感谢您的帮助!
(*) It's seems somewhat that it does not really create the variables, but a string that looks like variables...