How to trim white spaces of array values in php


 
Many time we want to trim array value dynamically. But we always go with foreach and trim that value.

If we are not aware from “array_map” function then we used simply foreach function and used trim function.

But its better to use following function. It will directy trim all value of array.

$arr = array('  Jainish ',' S  ','            Senjaliya ');
		
$trimmed_array  =  array_map('trim',$arr);

print_r($trimmed_array);

If you have any queries, please do not hesitate to contact me at Jainish Senjaliya

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s