Accessing Multi-Valued Parameters in PHP $_GET Array
PHP's $_GET superglobal array allows access to query string parameters. By default, when multiple values are assigned to the same parameter, only the last value is stored in $_GET. However, it is possible to retrieve such values as an array.
Creating Multi-Valued $_GET Parameters
To send multiple values for a parameter in a query string, simply use the square bracket notation:
http://link/foo.php?id[]=1&id[]=2&id[]=3
Accessing the Array in PHP
Using the above technique, $_GET['id'] will become an array containing the multiple values:
<code class="php">echo $_GET['id'][0]; // Output: 1 echo $_GET['id'][1]; // Output: 2 echo $_GET['id'][2]; // Output: 3</code>
By accessing $_GET['id'] as an array, you can iterate over the values and process them individually or as a collection.
Note: This method is compatible with most web servers and browsers. However, it's worth noting that some older servers may not support multi-valued parameters.
The above is the detailed content of How to Access Multi-Valued Parameters in PHP $_GET Array?. For more information, please follow other related articles on the PHP Chinese website!