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");
trim() The trim() method removes whitespace from both ends of a string and returns a new string, without modifying the original string.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With