Ver Mensaje Individual
  #1 (permalink)  
Antiguo 20/12/2010, 09:31
Biokari
 
Fecha de Ingreso: marzo-2009
Mensajes: 23
Antigüedad: 15 años, 7 meses
Puntos: 0
Problema con foreach tabla asociativa

Hola a todos!!!

Bueno, mi problema es que quiero recorrer 2 arrays asociativos simultaneamente y no logro hacerlo. Puedo recorrer los dos arrays y obtener bien los datos que quiero gracias a un foreach, pero yo quiero hacerlo simultaneamente y lo unico que logro hacer hasta ahora es hacer un foreach en un foreach y no me da el resultado que espero

yo quiero comparar por ejemplo:

$file_locus

Cita:
array(14)
{ ["pd_10"]=> array(2) { ["allele_1"]=> string(3) "123" ["allele_2"]=> string(3) "128" }
["Pd_15"]=> array(2) { ["allele_1"]=> string(3) "119" ["allele_2"]=> string(3) "152" }
["Pd_16"]=> array(2) { ["allele_1"]=> string(3) "111" ["allele_2"]=> string(3) "111" }
["Pd_25"]=> array(2) { ["allele_1"]=> string(3) "201" ["allele_2"]=> string(3) "201" }
["Pd_32"]=> array(2) { ["allele_1"]=> string(3) "287" ["allele_2"]=> string(3) "287" }
["Pd_35"]=> array(2) { ["allele_1"]=> string(3) "176" ["allele_2"]=> string(3) "176" }
["Pd_50"]=> array(2) { ["allele_1"]=> string(3) "206" ["allele_2"]=> string(3) "206" }
["Pd_57"]=> array(2) { ["allele_1"]=> string(3) "257" ["allele_2"]=> string(3) "259" }
["Pd_63"]=> array(2) { ["allele_1"]=> string(3) "141" ["allele_2"]=> string(3) "141" }
["Pd_70"]=> array(2) { ["allele_1"]=> string(3) "215" ["allele_2"]=> string(3) "215" }
["Pd_78"]=> array(2) { ["allele_1"]=> string(3) "136" ["allele_2"]=> string(3) "136" }
["Pd_85"]=> array(2) { ["allele_1"]=> string(3) "149" ["allele_2"]=> string(3) "149" }
["Pd_90"]=> array(2) { ["allele_1"]=> string(3) "137" ["allele_2"]=> string(3) "137" }
["Pd_93"]=> array(2) { ["allele_1"]=> string(3) "159" ["allele_2"]=> string(3) "159" }
}
con cada array de $bd_locus

Cita:
{ ["JCP967 P2_168"]=> array(14)
{ ["pd_10"]=> array(2) { ["allele_1_bd"]=> string(3) "123" ["allele_2_bd"]=> string(3) "127" }
["pd_15"]=> array(2) { ["allele_1_bd"]=> string(3) "119" ["allele_2_bd"]=> string(3) "152" }
["pd_16"]=> array(2) { ["allele_1_bd"]=> string(3) "111" ["allele_2_bd"]=> string(3) "117" }
["pd_25"]=> array(2) { ["allele_1_bd"]=> string(3) "201" ["allele_2_bd"]=> string(3) "201" }
["pd_32"]=> array(2) { ["allele_1_bd"]=> string(3) "285" ["allele_2_bd"]=> string(3) "299" }
["pd_35"]=> array(2) { ["allele_1_bd"]=> string(3) "176" ["allele_2_bd"]=> string(3) "176" }
["pd_50"]=> array(2) { ["allele_1_bd"]=> string(3) "170" ["allele_2_bd"]=> string(3) "210" }
["pd_57"]=> array(2) { ["allele_1_bd"]=> string(3) "271" ["allele_2_bd"]=> string(3) "271" }
["pd_63"]=> array(2) { ["allele_1_bd"]=> string(3) "141" ["allele_2_bd"]=> string(3) "150" }
["pd_70"]=> array(2) { ["allele_1_bd"]=> string(3) "195" ["allele_2_bd"]=> string(3) "195" }
["pd_78"]=> array(2) { ["allele_1_bd"]=> string(3) "125" ["allele_2_bd"]=> string(3) "125" }
["pd_85"]=> array(2) { ["allele_1_bd"]=> string(3) "149" ["allele_2_bd"]=> string(3) "155" }
["pd_90"]=> array(2) { ["allele_1_bd"]=> string(3) "137" ["allele_2_bd"]=> string(3) "165" }
["pd_93"]=> array(2) { ["allele_1_bd"]=> string(3) "157" ["allele_2_bd"]=> string(3) "159" } }


["JCP 188"]=> array(14) {
["pd_10"]=> array(2) { ["allele_1_bd"]=> string(3) "133" ["allele_2_bd"]=> string(3) "146" }
["pd_15"]=> array(2) { ["allele_1_bd"]=> string(3) "114" ["allele_2_bd"]=> string(3) "118" }
["pd_16"]=> array(2) { ["allele_1_bd"]=> string(3) "112" ["allele_2_bd"]=> string(3) "119" }
["pd_25"]=> array(2) { ["allele_1_bd"]=> string(3) "201" ["allele_2_bd"]=> string(3) "203" }
["pd_32"]=> array(2) { ["allele_1_bd"]=> string(3) "289" ["allele_2_bd"]=> string(3) "297" }
["pd_35"]=> array(2) { ["allele_1_bd"]=> string(3) "176" ["allele_2_bd"]=> string(3) "176" }
["pd_50"]=> array(2) { ["allele_1_bd"]=> string(3) "161" ["allele_2_bd"]=> string(3) "162" }
["pd_57"]=> array(2) { ["allele_1_bd"]=> string(3) "270" ["allele_2_bd"]=> string(3) "270" }
["pd_63"]=> array(2) { ["allele_1_bd"]=> string(3) "144" ["allele_2_bd"]=> string(3) "171" }
["pd_70"]=> array(2) { ["allele_1_bd"]=> string(3) "169" ["allele_2_bd"]=> string(3) "170" }
["pd_78"]=> array(2) { ["allele_1_bd"]=> string(3) "107" ["allele_2_bd"]=> string(3) "107" }
["pd_85"]=> array(2) { ["allele_1_bd"]=> string(3) "158" ["allele_2_bd"]=> string(3) "158" }
["pd_90"]=> array(2) { ["allele_1_bd"]=> string(3) "144" ["allele_2_bd"]=> string(3) "157" }
["pd_93"]=> array(2) { ["allele_1_bd"]=> string(3) "155" ["allele_2_bd"]=> string(3) "163" } }


["JCP 429"]=> array(14) {
["pd_10"]=> array(2) { ["allele_1_bd"]=> string(3) "135" ["allele_2_bd"]=> string(3) "163" }
["pd_15"]=> array(2) { ["allele_1_bd"]=> string(3) "125" ["allele_2_bd"]=> string(3) "138" }
["pd_16"]=> array(2) { ["allele_1_bd"]=> string(3) "128" ["allele_2_bd"]=> string(3) "130" }
["pd_25"]=> array(2) { ["allele_1_bd"]=> string(3) "201" ["allele_2_bd"]=> string(3) "201" }
["pd_32"]=> array(2) { ["allele_1_bd"]=> string(3) "295" ["allele_2_bd"]=> string(3) "295" }
["pd_35"]=> array(2) { ["allele_1_bd"]=> string(3) "186" ["allele_2_bd"]=> string(3) "186" }
["pd_50"]=> array(2) { ["allele_1_bd"]=> string(3) "191" ["allele_2_bd"]=> string(3) "191" }
["pd_57"]=> array(2) { ["allele_1_bd"]=> string(3) "255" ["allele_2_bd"]=> string(3) "263" }
["pd_63"]=> array(2) { ["allele_1_bd"]=> string(3) "152" ["allele_2_bd"]=> string(3) "152" }
["pd_70"]=> array(2) { ["allele_1_bd"]=> string(3) "192" ["allele_2_bd"]=> string(3) "192" }
["pd_78"]=> array(2) { ["allele_1_bd"]=> string(3) "124" ["allele_2_bd"]=> string(3) "147" }
["pd_85"]=> array(2) { ["allele_1_bd"]=> string(3) "159" ["allele_2_bd"]=> string(3) "165" }
["pd_90"]=> array(2) { ["allele_1_bd"]=> string(3) "161" ["allele_2_bd"]=> string(3) "172" }
["pd_93"]=> array(2) { ["allele_1_bd"]=> string(3) "173" ["allele_2_bd"]=> string(3) "173" } } etc ...
Para eso yo hago esto

Cita:
//recuperacion de datos primera tabla
foreach ($bd_locus as $bd_acc_name => $bd_tab_locus)
{
foreach ($bd_tab_locus as $bd_locus_name => $bd_tab_allele)
{

//recuperacion de datos segunda tabla
foreach($file_locus as $locusName=>$tab_allele)
{

echo "locus BD = ".$bd_locus_name."----allele 1 bd = ".$bd_tab_allele['allele_1_bd']."----allele 2 bd =".$bd_tab_allele['allele_2_bd']."<br> Locus file = ".$locusName."----allele 1 file = ".$tab_allele['allele_1']."----allele 2 file =".$tab_allele['allele_2']."<br><br>";

}
}
}
Y eso me da

Cita:
locus BD = pd_10----allele 1 bd = 123----allele 2 bd =127
Locus file = pd_10----allele 1 file = 123----allele 2 file =128

locus BD = pd_10----allele 1 bd = 123----allele 2 bd =127
Locus file = pd_15----allele 1 file = 119----allele 2 file =152

locus BD = pd_10----allele 1 bd = 123----allele 2 bd =127
Locus file = pd_16----allele 1 file = 111----allele 2 file =111

locus BD = pd_10----allele 1 bd = 123----allele 2 bd =127
Locus file = pd_25----allele 1 file = 201----allele 2 file =201

locus BD = pd_10----allele 1 bd = 123----allele 2 bd =127
Locus file = pd_32----allele 1 file = 287----allele 2 file =287

etc...

locus BD = pd_15----allele 1 bd = 119----allele 2 bd =152
Locus file = pd_10----allele 1 file = 123----allele 2 file =128

locus BD = pd_15----allele 1 bd = 119----allele 2 bd =152
Locus file = pd_15----allele 1 file = 119----allele 2 file =152

locus BD = pd_15----allele 1 bd = 119----allele 2 bd =152
Locus file = pd_16----allele 1 file = 111----allele 2 file =111

locus BD = pd_15----allele 1 bd = 119----allele 2 bd =152
Locus file = pd_25----allele 1 file = 201----allele 2 file =201

etc...
Y yo lo que quiero es

Cita:
locus BD = pd_10----allele 1 bd = 123----allele 2 bd =127
Locus file = pd_10----allele 1 file = 123----allele 2 file =128

locus BD = pd_15----allele 1 bd = 123----allele 2 bd =127
Locus file = pd_15----allele 1 file = 119----allele 2 file =152

locus BD = pd_16----allele 1 bd = 123----allele 2 bd =127
Locus file = pd_16----allele 1 file = 111----allele 2 file =111

locus BD = pd_25----allele 1 bd = 123----allele 2 bd =127
Locus file = pd_25----allele 1 file = 201----allele 2 file =201

locus BD = pd_32----allele 1 bd = 123----allele 2 bd =127
Locus file = pd_32----allele 1 file = 287----allele 2 file =287

etc...
Se entiende?

Ojala puedan ayudarme

Saludos!!!!