0
我有这种大的表单,我通过槽后的方法到PHP页面..其中$POST
变量有2个数组,这可能会有点不同,取决于用户如何填写表单,以便我从$POST
变量中进行迭代,以查看它是否为数组,如果它是从表中创建一个表的值,则有时.next
的值似乎不会读取值一个数组,但在另一个数组中,它完全读取它。.next()在php中显示随机空白值
这是我对每个代码:
foreach($_POST as $var){
if(is_array($var)){
foreach($var as $x => $value){
if($value != ''){
switch ($x) {
case "nombreOtrosMeds":
$otrosMedicos.='
<table class="tg">
<tr>
<td class="tg-yw4l"><strong>Nombre: </strong> '.$value.'</td>
<td class="tg-yw4l"><strong>Dirección: </strong>'.next($var).'</td>
</tr>
<tr>
<td class="tg-yw4l"><strong>Teléfono: </strong>'.next($var).'</td>
<td class="tg-yw4l"><strong>Fax: </strong>'.next($var).'</td>
</tr>
</table>
';
break;
case "tipoCirugia":
$algunaCirugia.='
<table class="tg">
<tr>
<td class="tg-yw4l"><strong>Tipo de cirugía: </strong> '.$value.'</td>
<td class="tg-yw4l"><strong>Hospital: </strong>'.next($var).'</td>
<td class="tg-yw4l"><strong>Fecha de cirugía: </strong>'.next($var).'</td>
</tr>
</table>
';
break;
}
}
}
}
}
,你可以看到它在所有的情况下,但结果即时得到相同的是:
Tipo de cirugía: cirugia1 Hospital: Fecha de cirugía:
Tipo de cirugía: Cirugia2 Hospital: Hospital2 Fecha de cirugía: 2015-10-15
和数组都是这样:
[1] => Array
(
[nombreOtrosMeds] =>
[dirOtrosMeds] =>
[telOtrosMeds] =>
[faxOtrosMeds] =>
[tipoCirugia] => cirugia1
[hospital] => hospital1
[fechaCirugia] => 2015-10-07
[tipoNoCirugia] => hospitalizacion1
[Nohospital] => hospital hospitalizacion1
[fechaNoCirugia] => 2015-10-04
[tomaMedNombre] =>
[tomaMedDosis] =>
[tipoDroga] => droga1
[cantidadDroga] => cantidad droga 1
[tiempoDroga] => timepo droga 1
[tipoDieta] =>
[cantidadPesodDieta] =>
[fechaDieta] =>
)
[cirugias] => Sí
[2] => Array
(
[tipoCirugia] => Cirugia2
[hospital] => Hospital2
[fechaCirugia] => 2015-10-15
[tipoNoCirugia] => Hospitalizacion2
[Nohospital] => Hospital Hospitalizacion2
[fechaNoCirugia] => 2015-10-13
[tipoDroga] => droga 2
[cantidadDroga] => cantidad droga 2
[tiempoDroga] => tempo droga 2
)
原因首先,我必须迭代通过$ _POST变量,在那里我发现了2个数组,我必须重复一次,我在第二个foreach中使用下一个($ var),这是一个检查如果$ _POST的值是一个数组(如果是),那么它执行该表,然后下一个帮助我,因为它表示将内部数组指针向前推进一个位置以获取元素值,我需要 –
我认为这必须是更简单的方法来做到这一点你想为每种类型的cirugía获取数组元素? –
如果$ _POST变量是它的一个数组,那么我想首先获取[tipoCirugia]中的值放在一个表格行中,然后我现在[tipoCirugia]之后的下2个值是[hospital]和[fechaCirugia]我想把它们放在接下来的2个表格行 –