gpt4 book ai didi

php - 从复选框创建数组

转载 作者:可可西里 更新时间:2023-11-01 00:48:24 24 4
gpt4 key购买 nike

我不想从复选框创建一个数组。

我使用了array($_POST[test],$_POST[test1],$_POST[test2])它可以工作,但是如果数组的一次为 NULL,则该数组也为 NULL

所以我不想要的是,如果数组的一次为 NULL,则它不在数组中

像这样

$_POST['test']=NULL;
$_POST['test1']="ARAAY1";
$_POST['test2']="ARRAY2";

它将是 array($_POST[test1],$_POST[test2])

最佳答案

尝试类似的东西

<input type="checkbox" name="options[]" value="one"/> one<br/>
<input type="checkbox" name="options[]" value="tow"/> tow<br/>
<input type="checkbox" name="options[]" value="three"/> three<br/>



$checked = $_POST['options'];
for($i=0; $i < count($checked); $i++){
echo "Selected " . $checked[$i] . "<br/>";
}

关于php - 从复选框创建数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12870621/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com