- get_defined_vars: documentation ( source)
- print_r: documentation ( source)
- in_array: documentation ( source)
<?php
$a = 10;
$b = 20;
$c = 30;
$d = 40;
$defined_variables = get_defined_vars();
$variables2keep = array("a", "b", "c");
foreach($defined_variables as $variable => $value) if(!in_array($variable, $variables2keep)) unset($$variable);
print_r(get_defined_vars());