php - How can I insert an else statement to this foreach loop?

I am trying to add an else state to this quiz system to disable the quiz after taking it once.
Been doing several codes but I can't seem to figure out how to implement it.
<?php
foreach ($results as $result):
if((strtotime($result['sdatetime']) <= strtotime(date("Y-m-d h:i:sa")))
&& (strtotime($result['edatetime']) > strtotime(date("Y-m-d h:i:sa"))))
{
?>
<tr>
<td><?php echo $result['test_name'];?></td>
<td><?php echo $result['subject']; ?></td>
<td><?php echo $result['edatetime']; ?></td>
<td><a href="solveTest.php?var=<?php echo $result['test_id'];?>" class="btn btn-primary" name="submit">Start Test</a></td>
</tr>
<?php } ?>
<?php endforeach; ?>
Answer
Solution:
It is quite basics because in this code you can write else statement just after end of if statement. it allows you to shows result if condition is true then execute code write under if statement otherwise execute code write in else statement.
<?php foreach ($results as $result):
if((strtotime($result['sdatetime']) <= strtotime(date("Y-m-d h:i:sa"))) && (strtotime($result['edatetime']) > strtotime(date("Y-m-d h:i:sa"))) ){ ?>
<tr>
<td><?php echo $result['test_name'];?></td>
<td><?php echo $result['subject']; ?></td>
<td><?php echo $result['edatetime']; ?></td>
<td><a href="solveTest.php?var=<?php echo
$result['test_id'];?>" class="btn btn-primary" name="submit">Start Test</a></td>
</tr>
<?php } else { ?>
<!-- wtite your code here -->
<?php } ?>
<?php endforeach; ?>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: xml parsing error: no root element found
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.