PHP access all $_POST[] variables into an array?

前端 未结 3 582
清歌不尽
清歌不尽 2020-12-13 10:56

how to capture all fields in the $_POST VARIABLE? into an array?

$email = $_POST;
$emails = array_keys($email);
foreach($emails as $email) {
            


        
3条回答
  •  没有蜡笔的小新
    2020-12-13 11:44

    If you want to capture a list from a POSTed form, then use the array syntax trick instead of enumerated input field names:

    
    
    
    

    This way you need no guessing in PHP, because emails[] becomes an array implicitely then:

    print_r($_POST["emails"]);
    foreach ($_POST["emails"] as $email) {
    

    For database-escaping just use:

    $db_emails = array_map("mysql_real_escape_string", $_POST["emails"]);
    // that's an array too
    

提交回复
热议问题