PHP Post复选框返回空数组


PHP Post CheckBox Returned Empty Array

我已经用它来收集复选框值数组。

    <form action="example.php" method="post" name="deleteform">
    <input type="submit" value="delete"/>
    <table>
    <?php
    foreach ($memArray as $row) {
       echo "<tr align='"center'">
       <td><input type='"checkbox'" value='"".$row['cus_id']."'" name='"del[]'" /></td>";   
         echo "</tr>";  
    }
    ?>
    </table>
</form

>

如果表单已张贴,则执行

    $delArray = $_POST['del'];
    print_r($delArray);

但结果返回Array,但内部没有任何内容

我把name改为del,而不是name改为del[],这很有效。但当我把[]加回来时,它返回空数组

您应该检查两件事。

一是形式方法。无论是post还是get。。

第二,当您提交页面时,复选框是否被选中。如果未选中,则$_GET或$_POST 中不能有数组

这是您的代码,尽管我已经对循环进行了更改。checkbox.php是当前文件名。

    <?php
    if(isset($_POST['delete']))
    {
        print_r($_POST['del']);
    }
?>
<form action="checkbox.php" method="post" name="deleteform">
<input type="submit" value="delete" name="delete"/>
<table>
<?php
for($i=0;$i<5;$i++) {
   echo "<tr align='"center'">
   <td><input type='"checkbox'" value='"".$i."'" name='"del[]'" /></td>";
     echo "</tr>";  
}
?>
</table>

将其与您的代码进行比较。提交后,您肯定会得到数组。