我有一个这样的数组:
array(28) {
[0]=> array(8) { ["jornada"]=> string(1) "1" ["team1"]=> string(12) "LEGANES F.C." ["team2"]=> string(9) "LAS CONOS" }
[1]=> array(8) { ["jornada"]=> string(1) "1" ["team1"]=> string(13) "BABACHAS F.C." ["team2"]=> string(19) "QUIRQUINCHAS VERDES" }
[2]=> array(8) { ["jornada"]=> string(1) "2" ["team1"]=> string(7) "TSU CHU" ["team2"]=> string(12) "SANTINO F.C." }
[3]=> array(8) { ["jornada"]=> string(1) "2" ["team1"]=> string(11) "LIBERO F.C." ["team2"]=> string(9) "LAS PUMAS" }
[4]=> array(8) { ["jornada"]=> string(1) "3" ["team1"]=> string(6) "PUCARA" ["team2"]=> string(15) "EL REJUNTE F.C." }
我的问题是,我怎样才能获得不同的“jornada”值?因为我必须通过“jornada”进行夹具分组,例如:
jornada 1 :
LEGANES vs LAS CONOS
BABACHAS vs QUIRQUINCHAS
jornada 2:
TSU CHU vs SANTINO
LIBERO vs LAS PUMAS
感谢您的帮助,对不起我的英语。
答案 0 :(得分:1)
您可以将它们重新排列成具有此分组的新数组...
$grouped = array();
foreach ($data as $row) {
$grouped[$row['jornada']][] = $row;
}
现在你可以这样做:
foreach ($grouped as $jorndada => $matches) {
echo "Jornada $jornada\n";
foreach ($matches as $match) {
echo $match["team1"] ." vs ". $match["team2"] . PHP_EOL;
}
}