• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

使用表单传递关联数组的例子_PHP

php 搞代码 3年前 (2022-01-25) 24次浏览 已收录 0个评论

今天从

www.php.net的用户反馈处看到如下警告讲到通过表单传递的关联数组不能被

each()函数读取我尝试了如下的操作没有发现问题结果完全正确。程序如下

//test1.php

//test2.php

<?

$msg = each($var);

echo $msg[0],$msg[1],$msg[‘key’],$msg[‘value’];

?>

//output is

8eccbad8e776ephp20008eccbad8e776ephp2000

原文 http://www.php.net/manual/ref.array.php

garbepat@ifrance.com

08Jan2001 09:52

Be careful if you want to submit a variable as an associative array.

If for some reason you use indexes that begin wit

……本2文来源gaodai.ma#com搞##代!^码@网3

搞代gaodaima码h a number for instance some dynamically

display ID number :

<input type=“textfield” name=“vars[8eccbad8e776e]”>

It seems to be a rare case but I needed to code that stuff.

The bug here comes from the fact the browser “urlencodes” the name of the field.

The array is actually transmitted but you can‘t use the “each()” function on It. However I can

swear you the array is not empty and – that’s worse the correct data is stored at the correct

index (is knew It making ‘echo $vars[“8ecc…”]’).

The less boring solution I found is to put an “_” before any index.

Then you will surely find a way to remove it using “preg_replace” for instance.


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:使用表单传递关联数组的例子_PHP

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址