我是PHP的新手,想让这些数组通过表单发送,但是无法设法将其存储在变量中并对其进行访问
HTML
<form action="./index.php" method="post">
<select name="multicheckbox[]" multiple="multiple" class="4colactive">
<option value="LunVie" name="LunVie">Lunes a Viernes</option>
<option value="LunSab" name="LunSab">Lunes a Sábados</option>
<option value="Todos" name="Todos">Todos los días</option>
<option value="Otros" name="Otros">Otros</option>
</select>
<button type="submit">Enviar</button>
</form>
PHP
<?php
$values = $_POST["multicheckbox"];
echo $values[2];
?>
multicheckbox
是一个数组,对其进行迭代。
foreach($_POST["multicheckbox"] as $check) {
echo $check . "<br />\n";
}
也请注意,option
没有name
,select
有name
。 https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option
<select name="multicheckbox[]" multiple="multiple" class="4colactive">
<option value="LunVie">Lunes a Viernes</option>
<option value="LunSab">Lunes a Sábados</option>
<option value="Todos">Todos los días</option>
<option value="Otros">Otros</option>
</select>