To get to the point I always wanted to use trim and apply it to the elements of the array. One work around is to loop through each element and apply the trim to each element but an easier way is to use PHP's native function array_map(). An easy implementation from the code below.
$myArray = array('one', ' two ', ' three', 'four ');
$trimmedArray = array_map('trim', $myArray);
That's it! One thing to note, if you have memory problems like me :) remembering syntax
you may get confused array_map with array_walk and or array_filter. Array_map() applies
the call back to each element of the array where as array_walk is most often used for walking over the array and just simply printing it. Although you can use array_walk also if you prefer.
Array_filters just filters the element using the call back and return the elements that satisfies you callback filter.
Hope it helps someone.