按数组值分组
我正在使用这段代码:
$permissions = array("canview", "canpostthreads", "canpostreplies", "canpostpolls", "all");
foreach($permissions as $permission) {
for ($i = 1; $i <= 5; $i++) {
$mode = $_POST['permission'][$i][$permission];
if($mode == 1)
echo "{$permission} = {$i}:::";
}
}
如果我选中一些复选框,输出是:
canview = 1:::canview = 5:::canpostreplies = 3:::canpostpolls = 5:::
我不希望输出如下:
而不是 canview = 1:::canview = 5:
canview = 1,5
并且如果我'例如:
canpostpolls = 1:::canpostpolls = 2:::canpostpolls = 3
它将是:
canpostpolls = 1,2,3:::canview = 1,5
我希望你们能理解。这是我自己的想法,你可以随意与我分享你的想法,这个数据将导出到mysql表中。
I'm using this code:
$permissions = array("canview", "canpostthreads", "canpostreplies", "canpostpolls", "all");
foreach($permissions as $permission) {
for ($i = 1; $i <= 5; $i++) {
$mode = $_POST['permission'][$i][$permission];
if($mode == 1)
echo "{$permission} = {$i}:::";
}
}
And the output if I check some checkboxes is:
canview = 1:::canview = 5:::canpostreplies = 3:::canpostpolls = 5:::
I wan't the output to be following:
instead of canview = 1:::canview = 5:
canview = 1,5
and if I'll have for example:
canpostpolls = 1:::canpostpolls = 2:::canpostpolls = 3
It'll be:
canpostpolls = 1,2,3:::canview = 1,5
I hope you understand it guys. This is my own idea for this, you are free to share your ideas with me, this data will be exported to the mysql table.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要更多地过滤数据...也许是这样的:
然后,您可以执行以下操作:
希望有帮助!
You need to filter your data a bit more... maybe something like this:
Then, you can do something like:
Hope that helps!
您可以执行类似的操作 - 本质上是在输出值之前将它们组合起来。
You can do something like this - essentially, combining the values before outputting them.