// recursive function to trim data
function _trim($val){
if(is_array($val)){
return array_map('_trim',$val); // recurse if an array
} else {
return trim($val); // call php's trim function, if not an array
}
}
$post = []; // define an array to hold a trimmed, working copy of the submitted form data
// inside the form processing code, get a trimmed copy of the submitted form data
$post = array_map('_trim',$_POST);
// you would refernce the elements in $post in the rest of the code, i.e. $post['search_products']