I have an array as follows
$fruit = array(\' apple \',\'banana \', \' , \', \' cranberry \');
I want an array which conta
array_map('trim', $data) would convert all subarrays into null. If it is needed to trim spaces only for strings and leave other types as it is, you can use:
array_map('trim', $data)
null
$data = array_map( function ($item) { return is_string($item) ? trim($item) : $item; }, $data );