Monday, November 29, 2010

PHP's array_map and trim

I often used the trim function of PHP to arrays. If you look at the documentation of trim in php.net or are familiar with PHP, you would know that it accepts string as its main argument.

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);
var_dump($trimmedArray);

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.

15 comments:

Unknown said...

Sergei , October 22, 1970 Born in Christian Louboutin Bois Dore Moscow State Ozherelye. Perhaps influenced by Cheap LV Handbags their parents worship warrior army, join the army in cheap jordans 1989, and into the elite airborne military service. 1991, by the influence of the Soviet Union, the uggs on sale Russian christian louboutin army general lack of funds, a large number ugg australia of Air Jordan 11 Gamma Blue soldiers seeking veterans, but under extremely difficult conditions still dedicated, praise superiors, and soon was sent to the famous christian louboutin shoes Ryazan Higher ugg Airborne Command School studies. After graduating in 1994, entered the famous Pskov 76th Guards Airborne discount christian louboutin Division, served as discount nike jordans the reconnaissance platoon, reconnaissance ugg soldes deputy company commander, company commander, battalion airborne regiment scouting director and other duties.From 2000 to Cheap Louis Vuitton Handbags 2004, where the forces have repeatedly ordered war with Chechen militants. Because of their opponents in order to form the squad activity and haunted impermanence, the Russians had to ugg boots mobilize elite troops set up large uggs outlet number of small units, "a Discount Louis Vuitton small wholesale jordan shoes play small" Implementation siege. commanding troops in Chechnya, Christian Louboutin Daffodile Ingushetia and other places over the mountains, to track the militants fled. Discount LV Handbags Although the militants were extremely vigilant, but as long as the task has never had outsmarted.August 8, 2008, Georgia suddenly invade South Ossetia (Russian peacekeepers stationed ugg pas cher there), the Russian military to respond quickly, including including the 76th Guards Airborne Division, more than christian louboutin remise 50% 3,000 people were immediately delivered to the pro-Russian Abkhazia, Georgia cheap nike jordan shoes Army contain two infantry brigades, effectively coordinate the cheap christian louboutin direction of the Russian Bags Louis Vuitton troops in South Ossetia.

Unknown said...



15.07.20fangyanting
replica watches rolex
oakley store
soccer outlet
nike air force pas cher
burberry outlet online
true religion sale
ralph lauren uk outlet
prada shoes
michael kors handbags
michael kors handbags
polo ralph lauren uk
cheap oakley sunglasses
louboutin
air max uk
toms shoes sale
christian louboutin
cheap jordan shoes
ray ban sunglasses
longchamp
gucci handbags
coach factory outlet
chanel online shop
polo ralph lauren
ray ban outlet
coach outlet online
pandora jewelry stores
tory burch shoes
retro jordans
pandora jewelry outlet
nike blazer high
coach factory outlet
kate spade
nike air max uk
cheap ray ban sunglasses
ray ban sunglasses

Unknown said...

2015-09-16 zhengjx
Ralph Lauren UK Sale Polo Shirts
Christian Louboutin Outlet For Women
ugg boots
Louis Vuitton Outlet Authentic Handbags Discount
michael kors handbags
Louis Vuitton Handbags Outlet On Sale
Louis Vuitton Outlet Purses and Handbags For Sale
canada goose
hermes birkin
New Jordans Cheap For Sale
Abercrombie & Fitch Clothing With Big Discount
Coach Factory Outlet Handbags 70% OFF
Lebron 12,11,10 Shoes For Sale
cheap uggs sale
Michael Kors Outlet Online Sale Free Shipping
Louis Vuitton Handbags Outlet Sale
Air Jordan 4 Retro Free Shipping
coach outlet store online
Louis Vuitton Handbags Outlet Stores Online
Ray Ban Sunglasses Outlet Store Online
ugg boots
michael kors handbag
michael kors outlet
Abercrombie And Fitch New York Clothing Warehouse
ralph lauren uk
Cheap Oakley Sunglasses Outlet With Discount
tory burch outlet
nike air max
Coach Outlet Store Online Free Shipping
Michael Kors Outlet USA Store

Unknown said...

ray ban sunglasses, http://www.raybansunglassesonline.us.com/
nike trainers, http://www.niketrainers.me.uk/
gucci handbags, http://www.guccihandbags-outlet.co.uk/
herve leger, http://www.herveleger.us.com/
timberland boots, http://www.timberlandboots.name/
coach outlet online, http://www.coachoutletonline-store.us.com/
michael kors outlet, http://www.michaelkorsoutletcanada.in.net/
juicy couture outlet, http://www.juicycoutureoutlet.net/
calvin klein underwear, http://www.calvinklein.in.net/
ray ban sunglasses, http://www.raybansunglass.us.com/
prada outlet, http://www.pradaoutlet.us/
lululemon outlet, http://www.lululemonoutletstore.in.net/
tory burch shoes, http://www.toryburchshoesoutlet.com/
michael kors outlet, http://www.michaelkorsoutlet.org.uk/
replica watches, http://www.replicawatchesforsale.us.com/
pandora jewelry, http://www.pandorajewelryoutlet.us.com/
nfl jerseys wholesale, http://www.nfljerseys-wholesale.us.com/
michael kors outlet, http://www.michaelkorsoutletonlinstore.us.com/
oakley outlet, http://www.oakleyoutlet.in.net/
oakley sunglasses, http://www.oakleysunglasses-outlet.us.com/
michael kors bags, http://www.michaelkorsbags.uk/
ray ban sunglasses, http://www.ray-bansunglasses.eu.com/
oakley sunglasses, http://www.oakley.in.net/
air max 2015, http://www.airmax2015.in.net/
the north face uk, http://www.thenorthfaces.org.uk/
swarovski outlet, http://www.swarovski-outlet.co.uk/
pandora jewelry, http://www.pandora.eu.com/
chanel handbags, http://www.chanelhandbags-outlet.co.uk/
1002maoqiuyun

chenlina said...

chenlina20151127
cheap air jordans
mont blanc pens
mulberry handbags
louis vuitton bags
cheap oakley sunglasses
nike huarache
replica watches
michael kors outlet online
toms wedges
louis vuitton handbags
ralph lauren uk
uggs boots for women
ray ban sunglasses outlet
nike air max
celine handbags
hollister co
soccer shoes
michael kors outlet clearance
louis vuitton outlet
uggs on sale
pandora jewelry
fake oakley sunglasses
cheap nfl jerseys
coach factory outlet
oakley sunglasses
jordan concords
coach factory outlet
michael kors handbags
beats by dre
burberry outlet
michael kors bag
celine outlet
louis vuitton outlet stores
michael kors outlet
canada goose jackets
oakley sunglasses cheap
polo ralph lauren
louis vuitton handbags
abercrombie and fitch
coach factory outlet
as

chenlina said...

chenlina20160127
coach outlet
chanel outlet
celine outlet
hollister shirts
ralph lauren uk
michael kors outlet clearance
adidas originals
michael kors outlet online
abercrombie and fitch
cheap ugg boots
coach outlet online
the north face outlet
mont blanc pens
tiffany and co
abercrombie outlet
coach outlet store
louis vuitton handbags
michael kors handbags
louis vuitton handbags
ray ban sunglasses
tory burch sale
coach outlet
abercrombie outlet
louis vuitton outlet online
ray ban sunglasses outlet
the north face outlet
coach factory outlet online
louis vuitton outlet
michael kors handbags
ralph lauren uk
lebron 13
abercrombie and fitch
louis vuitton outlet
oakley outlet
nike roshe run women
michael kors outlet
louis vuitton handbags
ray bans
canada goose outlet
coach factory outlet
as

Unknown said...

thomas sabo uk
herve leger outlet
coach outlet online
louis vuitton handbags
rolex watches
ugg boots
iphone case
cheap snapbacks
uggs outlet
michael kors outlet online
cartier outlet
michael kors outlet clearance
soccer jerseys
oakley sunglasses
celine outlet
canada goose outlet
coach outlet
futbol baratas
nike air force 1
longchamp outlet
coach outlet
michael kors outlet
ugg outlet
canada goose jackets
hermes birkin
polo ralph lauren
michael kors outlet store
air jordan 4
cheap uggs
tory burch outlet
tiffany and co jewelry
louis vuitton outlet
coach outlet
michael kors bags
ugg boots
chanyuan0913

xumeiqing said...

2016923meiqing
yeezy boost 350
jordan shoes
polo ralph lauren outlet online
true religion outlet
fitflops sale clearance
michael kors outlet online
gucci handbags
red bottoms outlet online
fit flops
pandora jewelry

Unknown said...


uggs outlet
seattle seahawks jerseys
adidas yeezy 350
ugg slippers
ray ban sunglasses
cheap uggs
pittsburgh steelers jerseys
uggs boots
oakley vault
ray ban sunglasses
louis vuitton outlet
cheap ray ban sunglasses
michael kors outlet
true religion uk
coach outlet online
coach outlet
fitflop shoes
ralph lauren polo
cheap jordans
christian louboutin
louis vuitton outlet
true religion outlet
uggs for women
cheap jordans
canada goose jackets
ray ban glasses
coach outlet
sac longchamp
pandora jewelry
rolex watches
basketball shoes
toms shoes
coach outlet online
ray ban outlet
ray ban wayfarer
oakley sunglasses
christian louboutin uk
canada goose
ugg boots uk
moncler jackets
201611.5wengdongdong


raybanoutlet001 said...

mont blanc pens outlet
vikings jerseys
nike huarache
converse trainers
armani exchange outlet
oklahoma city thunder
hollister clothing
michael kors handbags
toms shoes
ravens jerseys

Unknown said...

cheap oakley sunglasses
kate spade outlet
michael kors outlet
ed hardy
coach outlet online
coach factory outlet
browns jerseys
ugg boots
polo ralph lauren outlet
ugg boots

fgdfgcvcai said...

true religion jeans
cheap snapbacks
oakley sunglasses
fitflops shoes
fitflops
mbt shoes
fred perry polo shirts
ralph lauren uk
kate spade outlet
coach outlet online
20171012caihuali

zzyytt said...

yeezy boost 350
adidas yeezy boost
cheap nba jerseys
vibram fivefingers
air force ones
crazy explosive
adidas yeezy boost
ray ban sunglasses
nike huarache
huaraches

Unknown said...

qzz0710
calvin klein jeans
kate spade outlet
cheap jerseys
pandora charms
oakley sunglasses
fila shoes
christian louboutin outlet
ugg boots
cheap jordans
canada goose outlet

5689 said...

zzzzz2018.11.6
moncler jacket
michael kors outlet
ralph lauren
nba jerseys
coach outlet
pandora jewelry
moncler outlet
pandora
jordan uk
canada goose outlet