Reputation: 23208
Doing print_r on my array produces:
Array
(
[0] => dogs
[1] => cats
[2] => birds
)
The newline between cats and birds is causing a problem. I did the following and the spacing still persists: array_walk($arr,'trim');
What can be done to remove this spacing?
Upvotes: 3
Views: 131
Reputation:
array_walk
returns a boolean. Use array_map
instead:
$arr = array_map("trim", $arr);
Upvotes: 9
Reputation: 522626
array_walk
won't help you, since it does not by itself persist any changes to the data. Use array_map
instead:
$arr = array_map('trim', $arr);
If possible you should eliminate that extraneous line break from the beginning though, not filter it out after the fact.
Upvotes: 8