HTML Element Array, name="something[]" or name="something"?

HTML Element Array, name="something[]" or name="something"?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

HTML Element Array, name="something[]" or name="something"?

When handling form submissions in modern web applications, developers often encounter a specific syntactic choice that dictates how data is structured before it even reaches your backend: the use of square brackets in an input's name attribute. You might see <input name="education[]"> versus <input name="education">. While both approaches technically allow you to retrieve multiple values via standard mechanisms like PHP's $_POST or JavaScript's FormData, they represent fundamentally different design patterns with distinct implications for data structure and framework compatibility.

The primary distinction lies in how the server interprets the incoming payload. When you assign a name without brackets, such as name="education", you are telling the browser to treat this field as a scalar value. If a user fills out three education entries with this configuration, the browser serializes them into an array (e.g., ['Master', 'PhD', 'High School']). However, if your backend logic expects an associative structure or if the form contains mixed input types where some fields should remain single values while others are collections, the lack of brackets forces a flat array interpretation for that specific key.

Conversely, appending [] to the name attribute explicitly signals that the input field is intended to hold a collection within a larger object hierarchy. Consider the example <input name="education[]" value="PhD">. In PHP, this results in $_POST['education'] being an array immediately upon retrieval. The brackets act as a syntactic hint to frameworks like Laravel or Symfony that this key represents a list, not a scalar. This distinction becomes critical when dealing with nested forms or when you need to differentiate between a single value and a list using the same naming convention elsewhere in your form.

On the client side, specifically within JavaScript environments using FormData (which is how AJAX requests typically serialize data), the behavior mirrors the server-side expectations. If you iterate over a FormData object, the presence of [] ensures that the key remains distinct. Without it, if you were to append multiple entries with the exact same name but no brackets, they would overwrite each other in many legacy parsers, though modern browsers and frameworks like Laravel handle this gracefully by converting them into arrays regardless. However, relying on implicit conversion can lead to ambiguity when debugging or when migrating between different server-side languages where array detection might not be automatic.

A common pitfall arises when mixing these two styles within the same form without a clear architectural reason. If you define one field as name="skills[]" and another as name="skills", your backend will receive two separate keys: one holding an array of skills, and the other holding a single string value (or potentially overwriting it depending on the framework's specific handling of duplicate keys). This inconsistency often leads to runtime errors or unexpected data structures when deserializing the request into a DTO or model.

In the context of Laravel, which is widely adopted for robust backend logic, the distinction is less about capability and more about semantic clarity. The framework automatically handles both cases by populating arrays, but using [] aligns your frontend HTML with the expectation of a collection in your Eloquent models or typed properties. This reduces the cognitive load on developers reading the code; seeing education[] instantly communicates "this is a list" without needing to inspect the runtime data structure first.

Ultimately, the choice between name="something[]" and name="something" should be dictated by whether you are grouping these inputs as a logical collection in your application's domain model. If every instance of "education" belongs to a specific set, use []. If they are distinct, independent entities that just happen to share a label, a plain name might suffice, though consistency remains the golden rule for maintainable codebases.

Our network