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個表格行 –