这是我的HTML代码
<input type="checkbox" value="fotoğraf" name="materyal[]"> Fotoğraf
<input type="checkbox" value="resim" name="materyal[]">Resim
<input type="checkbox" value="çizelge" name="materyal[]">Çizelge
<input type="checkbox" value="katlanabilir harita" name="materyal[]"> Katlanabilir Harita
有复选框,我将取 $_POST['materyal'] 的值,然后如果值超过 1,我想用逗号写入屏幕值。 如果复选框值为空,我不写任何屏幕。
if (isset($_POST['materyal']) && !empty($_POST['materyal'])) {
$materyal = $_POST['materyal'];
echo "İçerdiği extra materyaller ; ";
foreach ($materyal as $materyallist) {
foreach ($materyallist as $yenimateryal){
array_push($sonmateryal, $yenimateryal);
}
}
echo implode(", ", $sonmateryal);
}
这是我的代码。 当我想在 if 连续中使用内爆时,我犯了错误。我该怎么做
似乎您只想显示内容?
$sonmateryal = array();
if (isset($_POST['materyal']) && !empty($_POST['materyal'])) {
echo "İçerdiği extra materyaller ; ";
foreach ($_POST['materyal'] as $materyallist) {
foreach ($materyallist as $yenimateryal) {
$sonmateryal[] = $yenimateryal;
}
}
}
echo implode(", ", $sonmateryal);
根据给定的 HTML 进行更新
if (!empty($_POST['materyal'])) {
echo "İçerdiği extra materyaller ; ".htmlentities(implode(',', $_POST['materyal']));
}
由于您将输入发布为简单数组,因此如果 post-ed 值不为空,这将用逗号内爆结果。