mysqli_real_escape_string() for entire $_POST array in php

1k Views Asked by At

I have $_POST with 20 keys. I want to apply mysqli_real_escape_string() for the entire $_POST array. So, should I apply mysqli_real_escape_string() to all 20 keys separately? Or is there any loop or any specific function available for it?

My Post array is like the example below:

$_POST =array(
      "A1"=>'xxxxxxxx',
      "A2"=>'xxxxxxxx',
      ........
      ........
      ........
      ..........
      .........
      .........
      "A20"=> 'xxxxxxxxx'
);
1

There are 1 best solutions below

4
Domenik Reitzner On

You can do something like this:

$escaped = array_map(function($var) use ($mysqli){
    return mysqli_real_escape_string($mysqli, $var);
},$_POST);