This sounds interesting, so I've given it a try:
function myCompact() {
$ret = array();
$argnum = func_num_args();
for ($i = 0; $i < $argnum; $i++) {
$varname = func_get_arg($i);
global $$varname;
$ret[$varname] = $$varname;
}
return $ret;
}
However, this function must be supplied with the name of the variables, not the variables themselves.