Q:

Write a PHP script to trim all the elements in an array using array_walk function

0

Write a PHP script to trim all the elements in an array using array_walk function

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now