ik有一个html表单,我可以在其中选择一些选项。我想将逗号分隔的值写入数据库。这是我的代码

$genretotal = $_POST['genre'];
$genre0 = $genretotal[0];
$genre1 = $genretotal[1];
$genre2 = $genretotal[2];
$genre3 = $genretotal[3];
$genre4 = $genretotal[4];
$genre5 = $genretotal[5];
$genre6 = $genretotal[6];
$genre7 = $genretotal[7];
$genre = $genre0 . "," . $genre1 . "," . $genre2 . "," . $genre3 . "," . $genre4 . "," . $genre5 . "," . $genre6 . "," . $genre7;


我怎样才能排除空值?

最佳答案

尝试使用implodearray_filter

implode(',', array_filter($_POST['genre']));

09-25 21:37