<?php
function trim_value(&$value)
{
$value = trim($value);
}
$fruit = array('apple','banana ', ' cranberry ');
var_dump($fruit);
array_walk($fruit, 'trim_value');
var_dump($fruit);
?>
Example #2
<?php
$string = 'This string has no whitespaces.';
echo ereg_replace( ' +', '', $string );
?>
Output: Thisstringhasnowhitespaces.