PHP Loop through form values

前端 未结 3 1569
清酒与你
清酒与你 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:06

    Also see the function explode()

    http://www.php.net/manual/en/function.explode.php

    0 讨论(0)
  • 2021-01-29 12:28

    You can loop over $_POST and read the values: http://www.php.net/manual/en/reserved.variables.post.php

    foreach($_POST as $key =>$value){
        // do something using key and value
    }
    
    0 讨论(0)
  • 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.
        }
    }
    
    0 讨论(0)
提交回复
热议问题