I saw another post suggesting using this statement to trim string variables contained in the array:
$_POST=array_map('trim', $_POST);
However, if in the first place, the strings are not contained in an array, I would like to have a trim function that can be used like this:
$a=' aaa ';
$b=' bbb ';
$c=' ccc ';
trimAll($a,$b,$c); //arbitrary number of string variables can be passed
I tried to write a function like this:
function trimAll() {
$args = &func_get_args();
foreach($args as &$arg) {
if(isset($arg) && is_string($arg))
$arg=&trim($arg);
}
//no return value is required
}
But without success, the string variables do not get trimmed after function return.
Why and how can this be done??