I have an array where some of its elements are filled with lots of whitespace and \n. I would like to remove this whitespace and \n.
I have been using the following code, but the compiler says that my code does not work for arrays.
//My code that removes white-space
$input = preg_replace( '/\s+/', ' ', $myArray);
//Sample of array with white space
$myArray = array(
'extra spaces' => '<div> </div>',
'return' => '<b>\n</b>',
)
//What I want the array to look like
$myArray = array(
'extra spaces' => '<div></div>',
'return' => '<b></b>',
)
array_walk(): "Applies [a] user-defined callback function to each element of [an] array." A simpleforeachloop will probably get you there, too.