How to implement random image display in a for loop in PHP
P粉852578075
2023-09-02 10:19:10
<p>I have a simple web page where I am trying to echo multiple images, my code is as follows</p>
<p>
<pre class="brush:html;toolbar:false;"><?php for($l=1;$l<=45;$l ){?>
<div class="thumb" style="background-image: url(l<?=$l?>.jpg);"></div>
<?php } ?></pre>
</p>
<p>So the pictures here are displayed in order from 1 to 45, but I want the pictures to be displayed in a random manner every time the page is loaded, can anyone tell me how to achieve this? Thank you in advance</p>
As mentioned in the comments, just create an array and shuffle it.