【问题标题】:GET values from variables with [] in url从 url 中带有 [] 的变量中获取值
【发布时间】:2019-10-21 15:11:11
【问题描述】:

我有这样的网址

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

如果我使用 echo $_GET[custom[weight]] 那么它不起作用。我如何检索这个值?

【问题讨论】:

  • 您可以像$_GET['custom']['weight'] 一样访问它,这将返回1$_GET['custom']['weight2'] 将返回2

标签: php url parameters get request


【解决方案1】:

您应该使用$_GET['custom']['weight']$_GET['custom']['weight2'] 访问它

你可以用print_r($_GET)检查它,你会得到类似的东西,

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

【讨论】:

    【解决方案2】:

    在提供的示例中,$_GET 变为多维,custom 是您想要的数组索引。

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

    【讨论】:

      猜你喜欢
      • 2012-07-13
      • 2016-04-25
      • 2015-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-17
      • 2017-03-12
      • 1970-01-01
      相关资源
      最近更新 更多