I'm building a form which has the following fields:
$k = 1;
foreach($ui_fmlSect_pg as $val)
{
$url_arr[] = $val;
echo '<tr>';
echo '<td><input size="1" type="text" name="freq_'.$k.'" id="freq_'.$k.'"
value="'.$udf_fmlS.'"></td></tr>';
++$k;
}
I would like to find a way to add the entered values, that is the content of the variable $udf_fmlS or any manual overwriting, from the *freq_$k* 开发者_StackOverflow中文版-named input fields into an array, but I'm not sure how to proceed with this, especially as the name and id are dynamically generated.
Thanks in advance for your help
You could do something like this:
$freq = array();
foreach ($_POST as $key => $val) {
// check for submitted data starting with freq_
if (substr($key, 0, 5) == 'freq_') {
// use the number after freq_ as the key and the value as the value
$freq[substr($key, 5)] = $val;
}
}
If I understand correctly, you will have variables like:
$_REQUEST['freq_0']
$_REQUEST['freq_1']
etc. You could do something like:
<?php
$freq_val_arr = array();
foreach($_REQUEST as $key => $val){
if (strpos($key, 'freq') === 0){
$freq_val_arr[] = $val;
}
}
Just change 'file_'.$k
to 'file[]'
or to 'file[' . $k . ']'
精彩评论