Tuesday, 14 August 2018

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);

0 comments:

Post a Comment