如何将数组中的所有字符串都修剪掉?(复制)

时间:2022-04-12 21:48:16

This question already has an answer here:

这个问题已经有了答案:

If I have this array:

如果我有这个数组:

array("  hey  ", "bla  ", "  test");

and I want to trim all of them, How can I do that?

我想把它们都剪掉,怎么做呢?

The array after the trim:

修剪后的阵列:

array("hey", "bla", "test");

2 个解决方案

#1


333  

array_map() is what you need:

array_map()是您需要的:

$result = array_map('trim', $source_array);

#2


47  

array_map() applies a given callback to every value of an array and return the results as a new array.

array_map()对数组的每个值应用一个给定的回调,并将结果作为一个新的数组返回。

$array = array_map('trim', $array);

#1


333  

array_map() is what you need:

array_map()是您需要的:

$result = array_map('trim', $source_array);

#2


47  

array_map() applies a given callback to every value of an array and return the results as a new array.

array_map()对数组的每个值应用一个给定的回调,并将结果作为一个新的数组返回。

$array = array_map('trim', $array);