在我的页面中我有许多可用的PHP变量eg. $a, $b, $f, $t, $er, $de12
然后我想使用foreach删除所有这些变量。我怎么能这样做?
我使用此代码但不起作用。它也显示错误
<?PHP
$ing_key ="1234567890";
$last = "love";
$phone = "088977";
$buff=($);
foreach($buff as $k=>$value){
if($k!=='') $[$k]=null;
}
echo $ing_key;
echo "<br>";
echo $last;
echo "<br>";
echo $phone;
?>
答案 0 :(得分:1)
此代码可满足您的需求:
$vars = array_keys(get_defined_vars());
foreach($vars as $var) {
unset(${"$var"}); # or may be reset them to empty string or set null# ${"$var"} = "";
}