开发者

How can I trim all strings in an Array? [duplicate]

开发者 https://www.devze.com 2023-03-21 16:07 出处:网络
This question already has answers here: How t开发者_运维百科o trim white spaces of array values in php
This question already has answers here: How t开发者_运维百科o trim white spaces of array values in php (15 answers) Closed 9 years ago.

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");


array_map() is what you need:

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


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

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

精彩评论

暂无评论...
验证码 换一张
取 消