Forum Moderators: coopster

Message Too Old, No Replies

trim() each member of an array

         

partha

7:07 pm on Jul 15, 2005 (gmt 0)

10+ Year Member



how do I apply the trim() function (removes whitespace from both ends of a string) to each member of an array?

mattx17

7:11 pm on Jul 15, 2005 (gmt 0)

10+ Year Member



See [php.net...]

sned

7:13 pm on Jul 15, 2005 (gmt 0)

10+ Year Member



You might be able to use the array_walk [us2.php.net] function.

Or, you could just loop through the array ...

foreach($array_name as $id=>$value){
$array_name[$id] = trim($value);
}

-sned

<edit>
Oo .. I haven't looked at the array_map function, looks cool
</edit>

Anyango

10:21 pm on Jul 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey! i would use this...

for($i=0;$i<count($yourArray);$i++)
{
$yourArray[$i]=trim($yourArray[$i]);
}