This question is an exact duplicate of:
this code causes the images to be displayed on a rotating basis on the site.
<?php
$myImagesList = array (
'image1.png' ,
'image2.png' ,
'image3.png' ,
'image4.png' ,
'image5.png' ,
'image6.png' ,
'image7.png' ,
'image8.png' ,
'image9.png' ,
'image10.png'
);
shuffle ($myImagesList);
echo '<div style = "background: #0600ff" class = "div02">';
for ($i=0; $i<10; $i++) {
if ($i < 5) {
echo '' . $myImagesList[$i] . '';
}
if ($i == 5) {
echo '</div>';
echo '<div style = "background: #0600ff" class = "div02">';
}
if ($i > 5) {
echo '' . $myImagesList[$i] . '';
}
}
echo '</div>';
?>
CONTENT
But how to break this code so that the loop with rotating images continues elsewhere on the site?
something like this
<?php
RANDOM IMAGES
?>
XXX HTML CODE XXX
<?php
CONTINUOUS RANDOM IMAGE
?>
</div>
Make 2 for
loops and do whatever you want in between the second loop.
<?php
$myImagesList = array (
'image1.png' ,
'image2.png' ,
'image3.png' ,
'image4.png' ,
'image5.png' ,
'image6.png' ,
'image7.png' ,
'image8.png' ,
'image9.png' ,
'image10.png'
);
for ($i=0; $i<5; $i++) {
echo $myImagesList[$i] . "
";
}
echo 'Start second loop' . "
";
//note no reassignment of $i
for ($i; $i<10; $i++) {
echo $myImagesList[$i] . "
";
}
Demo: https://eval.in/603402