PHP Loop through form values

前端 未结 3 1633
清酒与你
清酒与你 2021-01-29 12:02

I have a form that submits lots of small fields that I need to loop through and perform actions on.

The form looks like this:



        
3条回答
  •  梦谈多话
    2021-01-29 12:30

    Look into the use of explode() and POST variables.

    Try something along the lines of:

    // Loop over each item in the form.
    foreach($_POST as $name => $value) {
        // Split the name into an array on each underscore.
        $splitString = explode("_", $name);
    
        // If the data begins with "minnight", use it.
        if ($splitString[0] == "minnight") {
            // Set the other desired values into variables.
            $secondValue = $splitString[1];
            $thirdValue= $splitString[2];
    
            // Database query goes here.
        }
    }
    

提交回复
热议问题