PHP:?和&在URL中 - 有什么区别?

All*_*n S 2 php url

有什么区别?和&在URL?

例如 http://www.site.com/index.php?someVar=value&otherVar=value

bri*_*rns 14

?标记的开始查询字符串,将&被用于各个变量分离的查询字符串.

例如,我将修改您的示例以使其更清晰:

http://www.site.com/index.php?someVar=firstVal&otherVar=secondVal
Run Code Online (Sandbox Code Playgroud)

URL的"位置"部分是一切,但不包括?,所以它只是:

http://www.site.com/index.php
Run Code Online (Sandbox Code Playgroud)

这是您的Web服务器将用于查找要执行的脚本的内容.然后它将分离查询字符串(后面的所有内容?)并将其传递给您的脚本(或更准确地说,传递给PHP).查询字符串将全部为:

someVar=firstVal&otherVar=secondVal
Run Code Online (Sandbox Code Playgroud)

然后,PHP将使用&变量之间的分隔符来解析查询字符串.所以这个查询字符串将包含两个变量:someVarvalue firstValotherVarvalue secondVal.

PHP将在$_GET超全局变量中存储解析查询字符串的结果,该变量只是一个关联数组,其中键是参数的名称,值当然是关联值.

所以在PHP中,如果你var_dump($_GET)使用这个例子,它将如下所示:

array(2) {
  ["someVar"]=>
  string(5) "firstVal"
  ["otherVar"]=>
  string(5) "secondVal"
}
Run Code Online (Sandbox Code Playgroud)


Nan*_*nne 5

?意思是“参数来了”,所以它是第一个
&意思是“另一个参数来了”,所以它是连续值