我有这段代码,我无法为所有出现的错误创建一个警报(好像它是一个项目符号列表)
if(isset($error)){
foreach ($error as $error)
{
echo '<div class="alert alert-warning" role="alert">';
echo '<p>'.$error.'</p>';
echo '</div>';
}
}
答案 0 :(得分:0)
只需将警报移出循环
if(isset($error)){
echo '<ul class="alert alert-warning" role="alert">';
foreach ($error as $error)
{
echo '<li>'.$error.'</li>';
}
echo '</ul>';
}
答案 1 :(得分:0)
<div class="alert alert-warning" role="alert">
<ul>
<?php
if(isset($error)){
foreach ($error as $err)
{
echo '<li>'.$err.'</li>';
}
}
?>
</ul>
</div>
答案 2 :(得分:0)
像这样更改你的代码..希望它能为你效用
if(isset($error)){
$errAlert = '<div class="alert alert-warning" role="alert">';
foreach ($error as $err) {
$errAlert .= '<p>'.$err.'</p>';
}
$errAlert .= '</div>';
echo $errAlert; // print this variable where you want
}