经测试代码如下:
/**
* 遍历清除数组中所有字符串的两端空格
*
* @param
* @arrange (512.笔记) jb51.cc
**/
function TrimArray($Input){
if (!is_array($Input))
return trim($Input);
return array_map('TrimArray',$Input);
}
/*
Old version (v0.1):
function TrimArray($arr){
if (!is_array($arr)){ return $arr; }
while (list($key,$value) = each($arr)){
if (is_array($value)){
$arr[$key] = TrimArray($value);
}
else {
$arr[$key] = trim($value);
}
}
return $arr;
}
*/
//演示范例:
$DirtyArray = array(
'Key1' => ' Value 1 ','Key2' => ' Value 2 ','Key3' => array(
' Child Array Item 1 ',' Child Array Item 2'
)
);
$CleanArray = TrimArray($DirtyArray);
var_dump($CleanArray);
Result will be:
array(3) {
["Key1"]=>
string(7) "Value 1"
["Key2"]=>
string(7) "Value 2"
["Key3"]=>
array(2) {
[0]=>
string(18) "Child Array Item 1"
[1]=>
string(18) "Child Array Item 2"
}
}
*/
/*** 来自编程之家 jb51.cc(jb51.cc) ***/