This question already has an answer here:
这个问题已经有了答案:
- How to trim white spaces of array values in php 7 answers
- 如何在php 7中削减数组值的空格?
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 个解决方案
#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
#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);