Write a PHP script to trim all the elements in an array using array_walk function
<?php $colors = array( "Red ", " Green", "Black ", " White "); print_r($colors); array_walk($colors, create_function('&$val', '$val = trim($val);')); print_r($colors); ?>
Sample Output:
Array ( [0] => Red [1] => Green [2] => Black [3] => White ) Array ( [0] => Red [1] => Green [2] => Black [3] => White )
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
Array ( [0] => Red [1] => Green [2] => Black [3] => White ) Array ( [0] => Red [1] => Green [2] => Black [3] => White )need an explanation for this answer? contact us directly to get an explanation for this answer