I am aware of array_walk() and array_map(). However when using the former like so (on an old project) it failed
array_walk($_POST,
mysql_real_escape_string() won't work unless you've made a mysql connection first. The reason it is so cool is that it will escape characters in a way to fit the table type. The second [optional] argument is a reference to the mysql connection.
$_POST is always set up as key->value. So, you array_walk calls mysql_real_escape_string(value, key). Notice the second argument is not a reference.
That is why it does not work. There are several solution already mentioned above.