Is the order of INPUTS in a POST guaranteed for array inputs in PHP?

后端 未结 2 642
盖世英雄少女心
盖世英雄少女心 2020-12-10 11:08

I have a form where users enter an unbounded number of rows of data. They arrive at the form by entering whatever number of rows on the screen that they desire.

<         


        
相关标签:
2条回答
  • 2020-12-10 11:52

    It's sort of guaranteed by HTML4.01 (for -urlencoded, but it's assumed to be identical for /form-data), and all current browsers submit the form fields in the order they are listed in the document.

    So yes, they are ordered by their appearance, not by the random uuid.

    0 讨论(0)
  • 2020-12-10 11:55

    The W3 spec doesn't include rules on what order a form's values should be assembled into a data set, so technically you cannot be sure. On the other hand, I've not seen a case (from numerous browsers on numerous OSes over the years) where data hasn't been supplied in source-listing-order. I've not really tested for cases when changing the default (UI generated) tabindex values.

    You could always sort the array (asort) after you've received it to be sure about what order you're reading values.

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