Will data order in post form be the same to it in web form?

后端 未结 6 529
春和景丽
春和景丽 2021-01-13 00:25

Assuming there are 5 inputs in web form





        
6条回答
  •  迷失自我
    2021-01-13 00:47

    If you change the name of your input to the_same[] - $_REQUEST['the_same'] will become an array of those values, first to last in element order (all current browsers I believe).

    You can also specify a specific order if you need, or even use string keys. For instance, an would become $_REQUEST['the_same']['apple'][2]

    Without using the [] on the input names, PHP will only see the last value. The other values will be 'overwritten' by the later value when the $_REQUEST/$_GET/$_POST arrays are constructed.

    An example of using that to your advantage could be with a checkbox, as the HTML checkbox only submits a value when checked, you may want to submit a "not checked" value somtime:

    
    
    

提交回复
热议问题