处理42复选框以某种形式 [英] dealing with 42 checkboxes in one form

查看:85
本文介绍了处理42复选框以某种形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的表格42复选框作为即时通讯,用户是选择他们的利益某一页进行编程。

通过命名所有的复选框兴趣,有没有让值数组的方法吗?

例如:

 <输入类型=复选框NAME =利息值=34/>
<输入类型=复选框NAME =利息值=19/>数组//值
$ interestArray [0] = 34;
$ interestArray [1] = 19;


解决方案

您正在寻找呢?

 <形式方法=POST行动=>
<输入类型=复选框NAME =兴趣[]VALUE =34/>
<输入类型=复选框NAME =兴趣[]值=19/>
<输入类型=复选框NAME =兴趣[]VALUE =56/>数组//值
$ _ POST ['兴趣'] [0] = 34;
$ _ POST ['兴趣'] [1] = 19;
$ _ POST ['兴趣'] [2] = 56;

指定数组的键名是HTML的可选项。如果不指定键名,则数组被填补的元素出现在表单中的顺序。

从PHP手册:怎样在一个HTML创建数组

I have 42 checkboxes in my form as im programming a page where the user is choosing their interests.

By naming all the checkboxes "interest", is there any way of making an array of values?

Example:

<input  type="checkbox" name="interest" value="34" />
<input  type="checkbox" name="interest" value="19" />

//values in array
$interestArray[0] = 34;
$interestArray[1] = 19;

解决方案

You're looking for this?

<form method="POST" action="">
<input  type="checkbox" name="interest[]" value="34" />
<input  type="checkbox" name="interest[]" value="19" />
<input  type="checkbox" name="interest[]" value="56" />

//values in array
$_POST['interest'][0] = 34;
$_POST['interest'][1] = 19;
$_POST['interest'][2] = 56;

Specifying an arrays key is optional in HTML. If you do not specify the keys, the array gets filled in the order the elements appear in the form.

From PHP manual: How do I create arrays in a HTML ?

这篇关于处理42复选框以某种形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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