- 在php中通过多维数组进行迭代

时间:2016-04-05 06:57:32

标签: php arrays

我有一个多维数组。要输出所有值,是否有比在下面循环遍历每个级别更简单的方法?

$results['English']['Listening'][] = 100;
$results['English']['Listening'][] = 80;
$results['English']['Exam'][] = 70;
$results['English']['Exam'][] = 90;
$results['Computer']['Exam'][] = 90;

foreach ($results as $subject => $data) {
    foreach ($data as $component => $scores) {
        foreach ($scores as $score) {
            echo "$subject => $component => $score" . "<br/>";
        }
    }
}

0 个答案:

没有答案