【发布时间】:2014-10-10 15:25:36
【问题描述】:
我有 2 个数组。
第一个数组包含文本中简单 DB 的表名。
第二个数组包含每个表的值。
当我启动表单时,从表单发送的字段值与表数组的值相同,从表单中获取值。
脚本:
<?php
if($_POST[send]=="ok") {
/// The structure it´s that and fixed , in the array_1 and 2 ///
$tables="name,phone,alias";
$values="Jhon,55543232,johny25";
/// Explode values in each case ///
$exp_tables=explode(",",$tables);
$exp_values=explode(",",$values);
/// Array for get values for each field ///
$i=0;
foreach($exp_tables as $exp_table) { ${$exp_table}[]="".$exp_values[$i].""; $i++; }
/// Bucle for get the result if vars send by form equal to the other vars and change by new value send form the form ///
foreach($exp_tables as $table) {
foreach($_POST as $key=>$value) {
if($table=="".$key."")
{
print "".$_POST[$table]."";
}
else { print "".${$table}{0}."";}
}
}
}
?>
html 表单
<form action="" method="post">
<input type="text" name="name" value="" />
<input type="submit" name="submit2" value"send" />
<input type="hidden" name="send" value="ok" />
</form>
在表单中,我在第一个字段中有“名称”,在数组表中,我有一个字段也称为名称。
当我发送表格时,我必须得到这个:
Jhon(change value by the value from the form),55543232,johny25
问题是重复所有时间值并且没有得到结果。
我的问题是:如何解决这个问题,以便放置我从表单发送的值,并在其他值与数组表中的名称相同时进行更改,但效果不是很好。
【问题讨论】:
-
你能告诉我你期望什么输出吗?您是说 $name 值应该替换为表单的值吗?
-
是的没错,与数组中同名的表单通过表单值发送改变值