计算复选框的值

时间:2011-10-21 17:39:17

标签: php arrays sum

我正在尝试总计所选复选框的值。我收到了个人价值观,但无法弄清楚如何将它们合计。

<?php 
$q1= isset($_POST["question1"])
? implode(',', $_POST["question1"])
: 'no selection made';
?>

这是我的复选框:

 <label>
          <input type="checkbox" name="question1[]" value="0" id="question1_0" />
          Not Applicable</label>
        <br />
        <label>
          <input type="checkbox" name="question1[]" value="7.69" id="question1_1" />
          Tells the truth.</label>
        <br />
        <label>
          <input type="checkbox" name="question1[]" value="7.69" id="question1_2" />
          Shows respect for others.</label>
        <br />
        <label>
          <input type="checkbox" name="question1[]" value="7.69" id="question1_3" />
          Is straight forward- does not have a "hidden agenda."</label>
        <br />
        <label>

1 个答案:

答案 0 :(得分:2)

很简单,只需使用array_sum

$q = empty($_POST["question1"]) ? 0 : array_sum($_POST["question1"]);
相关问题