Home » » Trim array values in php

Trim array values in php

Written By Unknown on Jumat, 27 September 2013 | 03.49


The trim() function of php removes whitespaces or some other character from a string like...

$trimmed = trim ($string);

In above example trim removes only whitespaces but you can remove any character by passing that character set into the function as second parameter like...

$trimmed = trim ($string, '/-');

This removes / and - from the string from left and right.

But when it comes to array what to do?

Just use the same trim() function with combination of another php function array_map() like...



$trimmed = array_map('trim', $array);


Above example will trim all array values.

array_map() is a very handy function while dealing with arrays.
Look at the another example of array_map() to Sort multidimensional array.

Share this article :

Posting Komentar

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Kumpulan Kata Broadcast Blackberry - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger