添加输入文件值并稍后将其保存在数据库中的最佳方法是什么。
我的输入字段如下所示:
<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"
]
]
但如果我数组求和并打印出值,我会得到一个0。
试试这个
$sum = 0;
if(isset($_POST['test']) && is_array($_POST['test'])){
$sum = array_sum(array_map('intval', $_POST['test']));
}