dtczp02204 2011-05-03 22:19
浏览 112
已采纳

PHP处理多维$ _REQUEST数组吗?

A great feature of PHP is that it handles arrays in request variables, so if you post a string like ...&test[one]=two&test[three]=four then you can access test as an array by using $_REQUEST['test'].

However I've discovered today that there's a problem with multi-dimension $_REQUEST arrays, and I'm wondering if there's a way around it.

To test, I used a form with the fields:

<input name="one[one]" />
<input name="one[two]" />
<input name="three[four[five]]" />
<input name="three[four[six]]" />

Once this was submitted, I used var_dump to see the array structure:

array(3) {
  ["one"]=>
  array(2) {
    ["one"]=>
    string(0) ""
    ["two"]=>
    string(0) ""
  }
  ["three"]=>
  array(2) {
    ["four[five"]=>
    string(0) ""
    ["four[six"]=>
    string(0) ""
  }
}

The one element is array-ified as expected. But the three element is not. Now I wouldn't mind if it just wasn't supported, but what's got me confused is the reason why. Look at the names of the sub-elements of three - four[five and four[six. It's not being interpreted as an array because for some reason the trailing ] which would help to identify these elements as array values has been lost!

Does anyone have an explanation for this? Is there any way around it, other than to only use a maximum of one level in $_REQUEST arrays?

  • 写回答

2条回答 默认 最新

  • dongwo1234 2011-05-03 22:21
    关注

    Try three[four][five] and three[four][six] instead.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法