【发布时间】:2014-06-19 08:37:32
【问题描述】:
我有 5 个不同的输入,用户可以填写或不填写
- 输入1:
- 输入2:
- 输入3:
- 输入4:
- 输入5:
总结每个输入都有状态0或1,未填充或已填充。
我需要做的是以简单快捷的方式获得所有 32 种组合。
我试图做的是这样的
i1 = trim($_POST['input1']);
i2 = trim($_POST['input2']);
i3 = trim($_POST['input3']);
i4 = trim($_POST['input4']);
i5 = trim($_POST['input5']);
if(empty(i1) and empty(i2) and empty(i3) and empty(i4) and empty(i5))
{
code = '00000';
sentence = sentencesql(code); // i have a sql for each combination
}
elseif (empty(i1) and empty(i2) and empty(i3) and empty(i4) and !empty(i5))
{
code = '00001';
sentence = sentencesql(code);
}
.
.
.
// each and every combination
.
.
elseif(!empty(i1) and !empty(i2) and !empty(i3) and !empty(i4) and !empty(i5))
{
code = '11111';
sentence = sentencesql(code);
}
这可行,但代码相当广泛
关于如何缩短代码的任何想法???
【问题讨论】:
-
PHP 中的变量用
$前缀表示。 -
是的,对不起,我忘记了 $
标签: php