[英]How to get both the text and value of a select box and store it into the database?
[英]how to get multiple values from single text box and store it in array and also store it in database
我可以使用php从一个输入文本框中获取多个值并将其存储在数组中吗? 我想从用户那里读取多个整数并将其存储在数组中,例如,我添加了一个输入文本和一个提交:
您可以通过这种方式进行。
在HTML中制作一个具有输入的表格,该输入应采用逗号分隔的整数值,如下所示:
<form action="url" method="POST">
<input id="dataInput" type="text" name="data" value="12,34,56">
<button id="submitBtn">Submit</button>
</form>
现在提交表单时,您应该使用PHP接收数据,并且可以使用php的explode
方法,如下所示:
<?php
$data = $_POST['data'];
$data_arr = explode(',', $data); // <----- explode the string here from commas
// Now you can store these values into the database
因此, $data_arr
的输出为:
$data_arr = array(
0 => '12',
1 => '34',
2 => '56'
);
希望这可以帮助!
使用explode ()函数,然后使用array_walk ()函数以确保获得NUMERIC值
<?php
// Assuming your method is POST
// and assuming the delimiter (entered by user) is UNITED as a COMMA ","
$_POST['input_name'] = explode(",", $_POST['input_name']);
$_POST['input_name'] = array_walk($_POST['input_name'], 'floatval');
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.