[英]PHP echo associative multi-dimensional array
I am trying to create a multi-dimensional associative array and display all of its values. 我试图创建一个多维关联数组并显示其所有值。
How do I do that using for loop? 我该如何使用for循环?
Similar code: 类似的代码:
$StudScore = array(
"Mary" => array(
"physics" => 35,
"maths" => 30,
"chemistry" => 39
),
"Tom" => array(
"physics" => 30,
"maths" => 32,
"chemistry" => 29
),
"Jon" => array(
"physics" => 31,
"maths" => 22,
"chemistry" => 39
)
);
Look at this recursive function and see if it fits: 查看此递归函数,看看是否适合:
function echoArray($array) {
foreach ($array as $key => $value) {
echo "<li>$key</li>";
if (is_array($value)) {
echo "<ul>";
echoArray($value);
echo "</ul>";
} else {
echo "<ul><li>$value</li></ul>";
}
}
}
Change the way you display each item as you wish. 根据需要更改显示每个项目的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.