How to trim white spaces of array values in php

I have an array as follows

$fruit = array('  apple ','banana   ', ' , ',     '            cranberry ');

I want an array which contains the values without the white spaces on either sides but it can contain empty values how to do this in php.the output array should be like this

$fruit = array('apple','banana', ',', 'cranberry');

15 Answers
15

Leave a Comment