如果> 3个选择的选项是相同的PHP

时间:2017-06-20 14:29:16

标签: php comparison selectedvalue

我试图解决这个问题,但无法深究它,所以请您帮忙。我能解释的最佳方式是举例。

假设您有6个选择框,用户从列表中选择项目,一旦提交,值将通过" GET"并在屏幕上显示结果。

我如何检查所选择的6个选项中的3个或更多是否相同?我知道如何从GET中获取选定的值,但不知道如何检查3个或更多是相同的选择。

非常感谢任何帮助。

此致

<select class="form-control">
            <option value="" disabled="" selected="">Select Choice</option>
            <option value="choice1" >Choice 1</option>
            <option value="choice1">Choice 2</option>
            <option value="choice1">Choice 3</option>
        </select>
<select class="form-control">
            <option value="" disabled="" selected="">Select Choice</option>
            <option value="choice1" >Choice 1</option>
            <option value="choice1">Choice 2</option>
            <option value="choice1">Choice 3</option>
        </select>
<select class="form-control">
            <option value="" disabled="" selected="">Select Choice</option>
            <option value="choice1" >Choice 1</option>
            <option value="choice1">Choice 2</option>
            <option value="choice1">Choice 3</option>
        </select>
<select class="form-control">
            <option value="" disabled="" selected="">Select Choice</option>
            <option value="choice1" >Choice 1</option>
            <option value="choice1">Choice 2</option>
            <option value="choice1">Choice 3</option>
        </select>
<select class="form-control">
            <option value="" disabled="" selected="">Select Choice</option>
            <option value="choice1" >Choice 1</option>
            <option value="choice1">Choice 2</option>
            <option value="choice1">Choice 3</option>
        </select>
<select class="form-control">
            <option value="" disabled="" selected="">Select Choice</option>
            <option value="choice1" >Choice 1</option>
            <option value="choice1">Choice 2</option>
            <option value="choice1">Choice 3</option>
        </select>

1 个答案:

答案 0 :(得分:1)

您的回答是@u_mulder首先提出的建议:Set Rng = Sheets("sheet1").Range("B2:B6") 'Input range of all fruits Set Rng_output = Sheets("sheet2").Range("B2") 'Output range For i = 1 To Rng.Cells.Count Set rng_values = Range(Rng.Cells(i).Offset(0, 1), Rng.Cells(i).End(xlToRight)) 'For each fruit taking the values to the right which need to be transposed If rng_values.Cells.Count < 16000 Then 'To ensure that it doesnt select till the right end of the sheet For j = 1 To rng_values.Cells.Count Rng_output.Value = Rng.Cells(i).Value Rng_output.Offset(0, 1).Value = rng_values.Cells(j).Value Set Rng_output = Rng_output.Offset(1, 0) 'Shifting the output row so that next value can be printed Next j End If Next i 在您的请求子集上。

但是,您首先必须为您的选择命名,例如

array_count_values

(这感觉就像它可以在循环中完成)

收集名称列表,例如

检查每个选择的次数:

<select name='select[]' class="form-control">
        <option value="" disabled="" selected="">Select Choice</option>
        <option value="choice1" >Choice 1</option>
        <option value="choice1">Choice 2</option>
        <option value="choice1">Choice 3</option>
    </select>
<select name='select[]' class="form-control">
        <option value="" disabled="" selected="">Select Choice</option>
        <option value="choice1" >Choice 1</option>
        <option value="choice1">Choice 2</option>
        <option value="choice1">Choice 3</option>
    </select>
<select name='select[]' class="form-control">
        <option value="" disabled="" selected="">Select Choice</option>
        <option value="choice1" >Choice 1</option>
        <option value="choice1">Choice 2</option>
        <option value="choice1">Choice 3</option>
    </select>
<select name='select[]' class="form-control">
        <option value="" disabled="" selected="">Select Choice</option>
        <option value="choice1" >Choice 1</option>
        <option value="choice1">Choice 2</option>
        <option value="choice1">Choice 3</option>
    </select>
<select name='select[]' class="form-control">
        <option value="" disabled="" selected="">Select Choice</option>
        <option value="choice1" >Choice 1</option>
        <option value="choice1">Choice 2</option>
        <option value="choice1">Choice 3</option>
    </select>
<select name='select[]' class="form-control">
        <option value="" disabled="" selected="">Select Choice</option>
        <option value="choice1" >Choice 1</option>
        <option value="choice1">Choice 2</option>
        <option value="choice1">Choice 3</option>
    </select>