Get the values from $i , with disturbed order

前端 未结 1 1756
我寻月下人不归
我寻月下人不归 2021-01-29 13:15
for ($i = 0; $i < count($name); $i++) 
   {
    //some output ommited

        

        
相关标签:
1条回答
  • 2021-01-29 13:54

    First you have to concat $i to name to get unique names:

    for ($i = 0; $i < count($name); $i++) 
    {
       echo "<td><input type='submit' value='Purchase' name='$name . $i'></td></tr>";
    }
    

    If $name is "name" then you will get "name1", "name2", "name3", etc.

    Then you can print_r($_REQUEST); to see the items submitted.

    You do not need a for loop to see which of the items is set, but if you want to loop through the REQUEST array you could do something like this:

    foreach($_REQUEST as $post_var) 
    {
        if('name' == substr($post_var, 0, 4))
        {
            echo $post_var . ' ';
        }
    }
    

    Result:

    name1 name2 name3

    0 讨论(0)
提交回复
热议问题