我试图在php中构建一个ap来学习外语。我有一个函数,它构建一个表单并开始测试。它看起来像:
public function test($pol_ang)
{
$words = $this->wordsArray();
if($pol_ang == 1)
{
$_SESSION['correctAnswers'] = $this->answersPolAng($words);
}else {$_SESSION['correctAnswers'] = $this->answersAngPol($words);}
if(isset($_POST['btn-confirm']))
{
$answer = strip_tags($_POST['txt_word']);
if($answer != "")
{
$_SESSION['usersAnswerArray'][$_SESSION['licznik']-1] = $answer;
$_SESSION['licznik']++;
}
if($_SESSION['licznik'] > count($words))
{
unset($_SESSION['licznik']);
$this->auth_user->redirect('result.php');
}
}
if(empty($_SESSION['licznik']))
{
$_SESSION['licznik'] = 1;
}
?>
<form method="post" class="form-signin">
<table class="table table-striped table-hover">
<thead>
<tr>
<th><?php echo $_SESSION['licznik'].' z '.count($words); ?></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<?php
$word = explode(";",$words[($_SESSION['licznik']-1)]);
if($pol_ang == 1)
{
?>
<td><?php echo $word[0]; ?></td>
<?php
}
else
{
?>
<td><?php echo $word[1]; ?></td>
<?php
}
?>
<td>-</td>
<td>
<div class="form-group">
<input type="text" class="form-control" name="txt_word" placeholder="Tłumaczenie" required />
<span id="check-e"></span>
</div>
</td>
</tr>
</tbody>
</table>
<hr />
<div class="form-group">
<button type="submit" name="btn-confirm" class="btn btn-default">
<i class="glyphicon glyphicon-log-in"></i> END
</button>
</div>
</form>
<?php
}
在前面的wordsArray()函数中爆炸类的变量,$ words变成一个数组:[0]->wordLanguage1;wordLanguage2, [1]->wordLanguage1;wordLanguage2 etc..
。
$ pol_ang是语言选项。如果等于1,则$ _SESSION ['correctAnswers']变为“wordsLanguage1”,如果等于0则变为“wordLanguage2”。
这个功能很好。但我想做的是在结束测试后我的功能应该重复询问用户输入错误的单词。我无法找到问题的解决方案