php 制作所有 GET 变量的数组

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3289758/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 09:14:54  来源:igfitidea点击:

Make array of all GET-variables

phparraysget

提问by Emil

I'm trying to make an array from all the GET-variables passed to a PHP script. So far I haven't found any way to do this.

我试图从传递给 PHP 脚本的所有 GET 变量中创建一个数组。到目前为止,我还没有找到任何方法来做到这一点。

Is this possible?

这可能吗?

回答by Pekka

It's already there by default:

默认情况下它已经存在:

print_r($_GET);  // for all GET variables
print_r($_POST); // for all POST variables

PHP docs on all available superglobals

所有可用超全局变量的 PHP 文档

回答by Sarfraz

There is a $_GETsuper global array to get all variables from query string.

有一个$_GET超级全局数组可以从查询字符串中获取所有变量。

// print all contents of $_GET array
print_r($_GET);

// print specific variable
echo $_GET['key_here'];

You can also use foreachloop to go through all of them like this:

您还可以使用foreach循环来遍历所有这些:

foreach($_GET as $key => $value)
{
   echo 'Key = ' . $key . '<br />';
   echo 'Value= ' . $value;
}

回答by Boris Delormas

GET variables are allready passed as an array

GET 变量已经作为数组传递

回答by Alexandre Van de Sande

extract($_REQUEST);

Will get every variable passed by post or get and make into a new variable

将获取通过 post 传递的每个变量或获取并生成一个新变量

回答by karlw

The $_REQUEST variable is:

$_REQUEST 变量是:

An associative array that by default contains the contents of $_GET, $_POST and $_COOKIE.

默认情况下包含 $_GET、$_POST 和 $_COOKIE 内容的关联数组。

http://www.php.net/manual/en/reserved.variables.request.php

http://www.php.net/manual/en/reserved.variables.request.php

That could help

这可能会有所帮助

回答by Pradeep Kumar Kushwaha

Get all GET params by :

通过以下方式获取所有 GET 参数:

$all_params = $_SERVER['QUERY_STRING']

$all_params = $_SERVER['QUERY_STRING']