Jump to content

Apply Trim on Whole Array?


Recommended Posts

Is there a way to apply the function trim() on a whole array, instead of applying it to the individual input fields one by one?


Here's the code:

$blurb1_title = array ( 

$blurb2_title = array ( 

$blurb3_title = array ( 


All those $_POST variables are input fields, and I would like to apply trim() to them so the spaces get removed.


Is there an efficient way to do it without having to apply it all individually, if yes, what would be the correct syntax?





Link to comment
Share on other sites

Oops I accidentally posted my reply to the other thread. Well here's the reply again.


Thanks PFM,


I tried to implement it but I was not able to do so, I tried the following:


function blurb_titles ($all_titles) {



array_walk ($blurb2_title, 'blurb_titles');


Which I added below the array list.


But this would only break my script.

Link to comment
Share on other sites

What I tried was


array_map (trim(), $blurb2_title);


Didn't think that your version will work too, but now that I look at it it seems obvious. Trim is no different than any other function, it's just global.



Thanks abra!

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.