Write a PHP script to remove all white spaces in an array
<?php $my_array = array(15, null, " ", -2, NULL, "", " \n", "Red", 54, "\t"); print_r($my_array); $result = array_filter($my_array, create_function('$x','return preg_match("#\S#", $x);')); print_r($result); ?>
Sample Output:
Array ( [0] => 15 [1] => [2] => [3] => -2 [4] => [5] => [6] => [7] => Red [8] => 54 [9] => ) Array ( [0] => 15 [3] => -2 [7] => Red [8] => 54 )
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] => 15 [1] => [2] => [3] => -2 [4] => [5] => [6] => [7] => Red [8] => 54 [9] => ) Array ( [0] => 15 [3] => -2 [7] => Red [8] => 54 )need an explanation for this answer? contact us directly to get an explanation for this answer