Php 从url中带有[]的变量获取值
我有一个这样的URLPhp 从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;
?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