我有下面的数组,我似乎无法弄清楚如何从阵列Team_1中提取信息并回显出其中的0 - 5值。
array (size=3)
'Team_1' =>
array (size=5)
0 => string '1199' (length=4)
1 => string '1182' (length=4)
2 => string '1105' (length=4)
3 => string '1212' (length=4)
4 => string '891' (length=3)
'Team_2' =>
array (size=5)
0 => string '' (length=0)
1 => string '' (length=0)
2 => string '' (length=0)
3 => string '' (length=0)
4 => string '' (length=0)
'Team_3' =>
array (size=5)
0 => string '' (length=0)
1 => string '' (length=0)
2 => string '' (length=0)
3 => string '' (length=0)
4 => string '' (length=0)
答案 0 :(得分:4)
键是Team_1,因此您可以直接引用它并执行foreach循环来执行回显(您可以添加任何要回显的html以格式化值)。
foreach ($arr['Team_1'] as $val) {
echo $val.'<br>';
}
如果您的目的是遍历所有团队并回显值
foreach ($teams as $team => $vals) {
echo $team;
foreach ($vals as $val) {
echo $val;
}
}
答案 1 :(得分:1)
$output1 = $array['Team_1'][0]; // Should output 1199
echo $output1;
OR
foreach ($array['Team_1'] as $data){
echo $data.'<br/>';
}