如何在PHP中显示两个不同的随机图像


How to show two different random images in PHP?

我需要显示两个不同的随机图像。我尝试了这个代码,但第二个图像显示了与第一个相同的图像。我必须用15个随机图像来复制这个。http://www.kometschuh.de/Example-Random-CSS3-Image-Flip-Effect.html对于每个<li>,我需要显示2个不同的随机图像

<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>

试试这个:

$imagesDir = 'images/tips/';
$images = glob($imagesDir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
$randomImage = $images[array_rand($images)]; // See comments

您可以向array_rand()发送第二个参数以获得大于1的值。

还可以看看这些链接:

http://askwebexpert.com/tutorials/how-to-display-random-images-from-a-directory-using-php/

php从目录生成随机图像

PHP从文件夹中提取随机图像