In PHP, the $_GET superglobal variable provides a way to access data sent from a web form or a URL query string. However, it's not immediately clear how to obtain values in the $_GET array as an array.
Let's consider a scenario where you want to send multiple values for the "id" parameter in a URL:
http://link/foo.php?id=1&id=2&id=3
If you attempt to access the "id" value using $_GET['id'], you'll only get the last value (in this case, "3"). To retrieve the values as an array, you can modify your URL to include square brackets ("[]") after the parameter name:
http://link/foo.php?id[]=1&id[]=2&id[]=3
Now, if you access $_GET['id'], you'll obtain an array containing all the "id" values:
print_r($_GET['id']); // Output: [1, 2, 3]
This approach allows you to easily access multiple values for a single parameter in your PHP code.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3