从复选框发布多维数组 [英] posting multidimensional array from checkbox

查看:53
本文介绍了从复选框发布多维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了几个有关从复选框发布数组的问题,但是我还没有看到任何尝试做我想做的事情的事情.

I have seen a couple of questions regarding posting arrays from checkboxes, however I havent seen anything attempting to do what I want to do.

我有一个复选框列表,这些复选框提交了从数据库中的数据的foreach循环中填充的数据.

I have a list of checkboxes that submit data populated in foreach loop of data from a database.

<input type="checkbox" name="phonelist[]" value="<?=strtoupper($device['id']);?>"/>

这是我目前为复选框电话列表返回多个项目的方式.怎么可能在复选框的相同值部分但在多维数组的另一个项目下添加另一个值?例如

This is how I am currently returning multiple items for the checkbox phone list. Howver is it possible to add another value in the same value section of the checkbox but under a different item in a multidimensional array? e.g

<input type="checkbox" name="phonelist[][]" value="<?=strtoupper($device['id']);?><?=strtoupper($device['another value']);?>"/>

我知道我的伪代码"是错误的,但我希望它能解决我希望实现的想法.

Im aware my "Psuedocode" is wrong but I hope it gets across the idea I wish to achieve.

推荐答案

我认为您最好采用这种方式:

I think you better approach it this way:

<input type="checkbox" name="phonelist[<?=strtoupper($device['id']);?>]" value="<?=strtoupper($device['id']);?>"/>

然后

<input type="checkbox" name="phonelist[<?=strtoupper($device['id']);?>][<?=strtoupper($device['another value']);?>]" value="<?=strtoupper($device['id']).strtoupper($device['another value']);?>"/>

因此,您仍然可以 foreach $ _ POST ['phonelist'] ,但保留参考值.

So you can still foreach $_POST['phonelist'] but keep a reference value.

这篇关于从复选框发布多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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