How to handle arrays in GET, POST upon receipt?

Hello! Tell me on the subject of what you need to process the arrays GET, POST, REQUEST?
For example, it is possible to run through the entire array and handle the parameters by using the trim () function as gaps anywhere and never need not at the beginning not at the end. For example, you can delete the resulting blank values to further code to check for their existence, because if they exist, then they are not empty.
That's actually the question, what are some other situations that can in one fell swoop remove ran 1 time on incoming data?
function filterGet($data){
 foreach($data as $key => $val){
 $data[$key] = filterGet($val);
 $data[$key] = trim($val);
 if(empty($data[$key])) unset($data[$key]);

 return $data;
June 10th 19 at 14:39
3 answers
June 10th 19 at 14:41
For each case all individually. For example, you POST om send user data that should be written to the database. Know exactly what options come on the backend, you need to pick up only their and to filter by regular expression, get rid of the trim or use validation. If you send a bunch of other values, they should just be ignored.
Gaps GET can only pass encoded in base64, in the usual case they are not.

The General principle of single - pick what you want. The rest is either ignored or return an error. Handle the entire array - not the best practice.
June 10th 19 at 14:43
The data should be filtered just before use. No need to do anything in advance.
June 10th 19 at 14:45
Yes, in principle all, the most basic trim. All further depends on the specific situation. I would not even remove the keys that are declared but have no values, because you can pass a parameter to a GET which does not require a value, but requires the presence of:
not to write page?print=1

And all modern methods the pre-processing of data to work with the database already include built-in shielding (pdo, mysqli) for them, too, there is no need to escape user data.

As a result, all pre-processing is reduced to the usual
$_POST = array_map('trim', $_POST);
and then, under the question whether it is necessary at all :)

Find more questions by tags PHP