note 53789 deleted from function.compact by peehaa
| From: | peehaa@php.net | Date: | Tue, 27 Sep 2016 13:59:24 +0000 |
| Subject: | note 53789 deleted from function.compact by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-206684@lists.php.net to get a copy of this message | ||
Note Submitter: hericklr at gmail dot com
----
The compact function doesn't work inside the classes or functions.
I think its escope is local...
Above it is a code to help about it.
Comments & Suggestions are welcome.
PS: Sorry for my poor english...
<?php
function x_compact()
{ if(func_num_args()==0)
{ return false; }
$m=array();
function attach($val)
{ global $m;
if((!is_numeric($val)) && array_key_exists($val,$GLOBALS))
{ $m[$val]=$GLOBALS[$val];}
}
function sub($par)
{ global $m;
if(is_array($par))
{ foreach($par as $cel)
{ if(is_array($cel))
{ sub($cel); }
else
{ attach($cel); }
}
}
else
{ attach($par); }
return $m;
}
for($i=0;$i<func_num_args();$i++)
{ $arg=func_get_arg($i);
sub($arg);
}
return sub($arg);
}
?>