How to Access Multi-Valued Parameters in PHP $_GET Array?

Patricia Arquette
Release: 2024-10-22 20:59:29
Original
600 people have browsed it

How to Access Multi-Valued Parameters in PHP $_GET Array?

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
Copy after login

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>
Copy after login

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!

source:php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!