I’m looking at websites that use php and I seea[]=val1 instead ofb=val2. My question is why are there brackets in the url? What type of code would produce this effect?
I’m looking at websites that use php and I see a[]=val1 instead of b=val2
Share
Why Are the Brackets in the URL?
The brackets are in the url to indicate that
val1is to be assigned the next position in the arraya. If you are confused about the blank part of the bracket, look at how php arrays work.What Kind of Code Would Produce This?
As for the code that would create such a url, it could either be an explicit definition by the coder or some other script, or it could be somehow created by a form using the
method="get"attribute.Example:
To create this, you can define an array as the
nameof an input field like so:Or you can just make a link (the
atag) with this url:To parse this url with PHP, you would use the
$_GETvariable to retrieve the values from the url:The printout of the
print_r($a)statement would look like this (if you wrapped it in a<pre>tag):