'ErrorException foreach() argument must be of type array|object, null given
Im using codeigniter 4, and this is my view. I need to get the result from database so I am using php inside the html. I keep getting error exception foreach, but my first foreach working while not the second one.
<div id="container">
<?php $array1 = array(); ?>
<?php $array2 = array(); ?>
<?php $array3 = array(); ?>
<?php $array4 = array(); ?>
<?php $array5 = array(); ?>
<?php $array6 = array(); ?>
<?php $array7 = array(); ?>
<?php $array8 = array(); ?>
<?php foreach($checks as $checkans){?>
<?php array_push($array1, $checkans);
} ?>
<!--STARTS ERROR HERE-->
<?php foreach($results as $res){?>
<?php array_push($array2, $res->answer);
array_push($array3, $res->quizID);
array_push($array4, $res->question);
array_push($array5, $res->choice1);
array_push($array6, $res->choice2);
array_push($array7, $res->choice3);
array_push($array8, $res->choice4);
} ?>
<?php
for ($x=0; $x<10; $x++){ ?>
<p><?=array3($x)?>.<?=array4($x)?></p>
<?php if($array2($x)!=$array1($x)) {?>
<p><span style="background-color: #FF9C9E"><?=$array1($x)?></span></p>
<p><span style="background-color: #ADFFB4"><?=$array2($x)?></span></p>
<?php } else { ?>
<p><span style="background-color: #ADFFB4"><?=$array1($x)?></span></p>
<?php }} ?>
</div>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
