Php 在数据库中添加输入字段值

Php add input field values in database

添加输入文件的值并稍后将它们保存在数据库中的最佳方法是什么。

我的输入字段如下所示:

<input type="checkbox" name="test[]" value="1">
<input type="checkbox" name="test[]" value="10">
<input type="checkbox" name="test[]" value="100">
<input type="checkbox" name="test[]" value="1000">
<input type="checkbox" name="test[]" value="10000">
<input type="checkbox" name="test[]" value="100000">
<input type="checkbox" name="test[]" value="1000000">

因此,如果我检查第一个字段并发送数据库保存 1,如果我检查前 3 个,数据库应保存 111(1+10+100) 等等...

编辑:

所以我尝试了你的建议。 打印出数组给出了这个:

array:1 [▼
  "test" => array:3 [▼
    0 => "1"
    1 => "10"
    2 => "100"
  ]
]

但是如果我 array_sum 打印出我得到的值 0.

试试这个

$sum = 0;
if(isset($_POST['test']) && is_array($_POST['test'])){
    $sum = array_sum(array_map('intval', $_POST['test']));
}