Assistance with understanding php urls -
i'm looking @ websites use php , seea[]=val1
instead ofb=val2
. question why there brackets in url? type of code produce effect?
why brackets in url?
the brackets in url indicate val1
assigned next position in array a
. if confused blank part of bracket, @ how php arrays work.
what kind of code produce this?
as code create such url, either explicit definition coder or other script, or somehow created form using method="get"
attribute.
example:
to create this, can define array name
of input field so:
<form method="get"> <input name="a[]" ... /> <input name="a[]" ... /> <input name="a[]" ... /> </form>
or can make link (the a
tag) url:
<a href="foo.php?a[]=val1&a[]=val2&a[]=val3">click me!</a>
parse url php, use $_get
variable retrieve values url:
<?php $a = $_get['a']; $val1 = $a[0]; $val2 = $a[1]; $val3 = $a[2]; ... print_r($a); ?>
the printout of print_r($a)
statement (if wrapped in <pre>
tag):
array ( => array ( 0 => 'val1', 1 => 'val2', 2 => 'val3' ) )
Comments
Post a Comment