在隐藏的HTML输入字段中使用方括号 [英] Using square brackets in hidden HTML input fields

查看:107
本文介绍了在隐藏的HTML输入字段中使用方括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在分析别人的PHP代码,我注意到输入HTML有许多隐藏的输入字段,名称以'[]'结尾,例如:

 < input type =hiddenname =ORDER_VALUE []value =34/> 
< input type =hiddenname =ORDER_VALUE []value =17/>

处理这个输入的PHP页面会获得像这样的每个值:

  foreach($ _REQUEST [ORDER_VALUE] as $ order_value){
/ ...
}

什么是'[]'用于?指定将有多个输入字段具有相同的名称?

解决方案

是的。基本上PHP会知道将所有这些具有相同名称的值粘贴到数组中。



顺便说一下,这适用于所有输入字段,而不仅仅是隐藏字段。 / p>

I am analyzing someone else's PHP code and I've noticed that the input HTML has many hidden input fields with names that end with '[]', for instance:

<input type="hidden" name="ORDER_VALUE[]" value="34" />
<input type="hidden" name="ORDER_VALUE[]" value="17" />

The PHP page that processes this input acquires each value like this:

foreach ($_REQUEST["ORDER_VALUE"] as $order_value) {
    /...
}

What is the '[]' used for? Specifying that there would be multiple input fields with the same name?

解决方案

Yes. Basically PHP will know to stick all of those values with the same name into an array.

This applies to all input fields, by the way, not just hidden ones.

这篇关于在隐藏的HTML输入字段中使用方括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆