[英]How I can get the Index of select in php
<span>Level</span><br>
<select name="exp" id="exp" required>
<option disabled selected hidden>Choose your level</option>
<option>without exp</option>
<option>up to 1 month</option>
<option>up to 3 months</option>
<option>up to 6 months</option>
<option>1 year or more</option>
</select>
PHP:
$exp = "";
if(!empty($_POST)){
$exp = $_POST['exp']; //here I get only the value??
calcularIMC($exp);
}
function calcularIMC($exp){ // comparisons I want to do
if($exp == "INDEX 0"){ ...... } // how I can get the value to do this comparations?
if($exp >= "INDEX 1"){ ...... }
}
为了进行测试,我将变量$exp
以字符串形式存储。 我想知道如何获取索引以进行上述示例中的比较。
如何获取选择索引?
您需要为选项设置值,然后这些值就是提交给服务器的值。
<select name="exp" id="exp" required>
<option disabled selected hidden>Choose your level</option>
<option value="0">without exp</option>
...
</select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.