如何在PHP中显示两个不同的随机图像?
i need to show 2 different random images.
i tried this code but the second image, show the same image of the first.
i have to replicate this but with 15 random images.
http://www.kometschuh.de/Example-Random-CSS3-Image-Flip-Effect.html
for each <li>
i need to show 2 different random images
<ul class="flip">
<?php
$all_images = glob("wp-content/themes/connexia/img-test/{*.jpg, *.JPG, *.JPEG, *.png, *.PNG}", GLOB_BRACE);
shuffle($all_images);
foreach ($all_images as $index => $image ) {
if ($index == 15) break; // Only print 15 images
$image_name = basename($image);
$image_name2 = basename($image++);
echo "<li>
<img src='/wp-content/themes/connexia/img-test/{$image_name}' />
<img src='/wp-content/themes/connexia/img-test/{$image_name2}' />
</li>";
}
?>
</ul>
我需要显示2个不同的随机图像。
i尝试此代码但第二个图像显示相同的图像 第一个。
i必须复制这个,但有15个随机图像。
http://www.kometschuh.de/Example-Random-CSS3-Image-Flip-Effect.html
每个&lt; li&gt; code>我需要显示2个不同的 随机图像 p>
&lt; ul class =“flip”&gt;
&lt;?php
$ all_images = glob(“wp-content / themes / connexia / img- test / {*。jpg,* .JPG,* .JPEG,* .png,* .PNG}“,GLOB_BRACE);
shuffle($ all_images);
foreach($ all_images as $ index = &gt; $ image){
if($ index == 15)break; //仅打印15张图片
$ image_name = basename($ image);
$ image_name2 = basename($ image ++);
echo“&lt; li&gt;
&lt; img src ='/ wp-content / themes / connexia / img-test / {$ image_name}'/&gt;
&lt; img src ='/ wp-content / themes / connexia / img-test / {$ image_name2}'/&gt;
&lt; / li&gt; ;“;
}
?&gt;
&lt; / ul&gt;
code> pre>
div>
Try this:
$imagesDir = 'images/tips/';
$images = glob($imagesDir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
$randomImage = $images[array_rand($images)]; // See comments
You can send a 2nd argument to array_rand() to get more than 1.
Also have a look at these links:
http://askwebexpert.com/tutorials/how-to-display-random-images-from-a-directory-using-php/