The $_GET array in PHP is a superglobal variable that can be used to obtain information sent via a URL query string. Typically, each key in the array represents a variable name, while the corresponding value contains the associated value. By default, the $_GET values are treated as strings.
However, it is possible to pass an array value in the $_GET query string. To do this, you need to use the following syntax:
http://link/foo.php?id[]=1&id[]=2&id[]=3
In this case, the "id" parameter becomes an array with three elements, each containing one of the values provided in the query string.
On the PHP side, you can access the array value using the following syntax:
<code class="php">$_GET['id'];</code>
This will return an array containing the three values that were passed in the query string.
Consider the following PHP script:
<code class="php"><?php if (isset($_GET['id'])) { print_r($_GET['id']); } ?></code>
If you access this script via a URL like the following:
http://link/foo.php?id[]=1&id[]=2&id[]=3
The script will output the following array:
Array ( [0] => 1 [1] => 2 [2] => 3 )
The above is the detailed content of How to Pass and Access Array Values in PHP $_GET?. For more information, please follow other related articles on the PHP Chinese website!