PHP-修剪数组中数组的值

PHP-修剪数组中数组的值,php,arrays,Php,Arrays,我正在尝试修剪数组中的所有值,但到目前为止,我无法正确使用数组遍历递归-在运行数组遍历递归后不会修剪这些值。(在这种情况下,$test返回true) 这是我目前的代码: $array = [ [ 'component' => 'string ', 'productID' => 1, 'no_cas' => '85085-34-3', 'no_einecs' => '285-364-0',

我正在尝试修剪数组中的所有值,但到目前为止,我无法正确使用数组遍历递归-在运行数组遍历递归后不会修剪这些值。(在这种情况下,$test返回true) 这是我目前的代码:

$array = [

    [
      'component' => 'string          ',
      'productID' => 1,
      'no_cas' => '85085-34-3',
      'no_einecs' => '285-364-0',
      'isComponent' => true

    ],
    [
      'component' => 'string2       ',
      'productID' => 2,
      'no_cas' => '92128-34-2',
      'no_einecs' => '295-728-0',
      'isComponent' => true
    ],

];

function trimAll($item, $key){
    return trim($item);
}

$test = array_walk_recursive($array, 'trimAll');

var_dump('<pre>', $test , '</pre>');die;
$array=[
[
'组件'=>'字符串',
“productID”=>1,
“否”=>“85085-34-3”,
“否”=>“285-364-0”,
“isComponent”=>正确
],
[
“组件”=>“字符串2”,
“productID”=>2,
“否”=>“92128-34-2”,
“否”=>“295-728-0”,
“isComponent”=>正确
],
];
函数trimAll($item,$key){
返回修剪(项目);
}
$test=array\u walk\u recursive($array,'trimAll');
变量转储(“$test”);死亡
我会使用:


函数trimAll(&$item){$item=trim($item);}
This works:)。非常感谢您的帮助:)和
array\u walk\u recursive
返回
bool
。打印
$array
。@NiettheDarkAbsol将此作为回答,以便Sasha能够接受并结束他的问题:)
array_map(
    function(array $a) {
        return array_map('trim', $a);
    },
    $array
);