[英]PHP: foreach loop inside a foreach loop for nested arrays
I'm reporting form errors to the user with a nested arrays, because there are different groups to the form and I want to show the errors as such: 我使用嵌套数组向用户报告表单错误,因为表单有不同的组,我想显示错误:
echo "<ul>\n";
foreach ($errors as $error) {
if (is_array($error)) {
echo "Item ".$i." error(s):\n";
echo "<ul>\n";
foreach ($error as $itemError) {
echo "<li>".$ItemError."</li>\n";
}
echo "</ul>\n";
} else {
echo "<li>".$error."</li>\n";
}
$i++;
}
echo "</ul>";
The nested arrays are recognized however the items in the nested arrays don't show up, so I get an empty sub list echoed. 嵌套数组被识别,但嵌套数组中的项目不会显示,所以我得到一个空的子列表回显。
检查变量的大小写: $itemError
/ $ItemError
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.