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条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀