<?php

function securityOnPost($array){ //$array
    foreach ($array as $key => $value){
        if(is_array($value)){ //If $value is an array
            securityOnPostKey($value,$key);
        } else {
            $_POST[$key] = mysql_real_escape_string($_POST[$key]);
}
    }
}

function securityOnPostKey($array, $key){ //$array
    foreach ($array as $keySub => $value){
        $_POST[$key][$keySub] = mysql_real_escape_string($_POST[$key][$keySub]);
}
}

if(isset($_POST['submit'])){
securityOnPost($_POST);
}
?>