Input array key names in quotes or not?

I was wondering if it makes any difference when naming a form element that is an array, if you don’t wrap it in quotes for example <input type=‘text’ name=‘txt[“someKey1”]’> VS <input type=‘text’ name=‘txt[someKey1]’> .

Would one method have any awkward side effects that developers should be aware of?

thanks all

I personally don’t quote them, simply because the resulting keys in the array (for PHP, at least) would also be quoted (which makes them less convenient to reference IMO).

Just out of curiosity though, why do you use single quotes for attribute values? Conventionally, double quotes are used.

Just out of curiosity though, why do you use single quotes for attribute values? Conventionally, double quotes are used.

I must confess, much to my shame, I am not consistent in my quote mark usage sometimes. (and sometime that just my PHP output… like if I have used single quotes around a sting variable so avoid concatenation, e.g.: $a= ‘name[“somename”]’; )

That’s good to know. I was concerned that some UAs removed the quotes ( or one type of quote over the other) Also that [“0”] ( string) would not behave the same as 0. Mainly my concern came from discovering some quirks when trying to use the name attribute for BOTH .js and PHP leverage.

In a loosely-typed language like PHP, that isn’t usually much of a problem (though specific value and type comparisons would have to be eschewed). The problem is that you would have to remember to include the quotes when referencing the array keys in PHP, like:


name["'somename'"];
// or
name['\\'somename\\''];

That’s also obviously not as clear than if the string keys did not contain quotes.

Actually it makes sense to go w/o quotes, I just concerned that when I targeted elements in .js I would need them…

kind alike finder the common denominator between .js and PHP