Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从url中带有[]的变量获取值_Php_Url_Parameters_Get_Request - Fatal编程技术网

Php 从url中带有[]的变量获取值

Php 从url中带有[]的变量获取值,php,url,parameters,get,request,Php,Url,Parameters,Get,Request,我有一个这样的URL ?custom[weight]=1&custom[weight2]=2 如果我使用echo$\u GET[custom[weight]]则它不起作用。如何检索此值?在所提供的示例中,$\u GET将变为多维,并且custom是您想要的数组索引 foreach( $_GET['custom'] as $index => $value) { echo $index . ' has the value of ' . $value . PHP_EOL;

我有一个这样的URL

?custom[weight]=1&custom[weight2]=2

如果我使用echo
$\u GET[custom[weight]]
则它不起作用。如何检索此值?

在所提供的示例中,
$\u GET
将变为多维,并且
custom
是您想要的数组索引

foreach( $_GET['custom'] as $index => $value) { 
     echo $index . ' has the value of ' .  $value . PHP_EOL; 
}

您应该使用
$\u GET['custom']['weight']
$\u GET['custom']['weight2']

您可以使用
print\r($\u GET)
检查它,您将得到如下结果:

Array
(
    [custom] => Array
        (
            [weight] => 1
            [weight2] => 2
        )
)


您可以像
$\u GET['custom']['weight']
那样访问它,这将返回
1
$\u GET['custom']['weight2']
将返回
2