【发布时间】:2016-05-30 14:56:31
【问题描述】:
我想在 PHP 中以相同的正确顺序随机播放 2 个循环(或函数)。
目前的代码如下:
<div class="overlay">
<?php
// Get the list of all files with .jpg extension in the directory and save it in an array named $images
$directory = "uploads/_gallery/*.jpg";
// Create an array of images found in the uploads directory
$images = glob($directory);
// Randomise/shuffle the images
shuffle($images);
foreach( $images as $image ):
if ($image) { ?>
<div class="slide">
<?php echo "<img src='" . $image . "'>"; ?>
</div>
<? }
endforeach;
?>
</div>
<div class="grid">
<?php
// Get the list of all files with .jpg extension in the directory and save it in an array named $images
$directory = "uploads/_gallery/thumbs/*.jpg";
// Create an array of images found in the uploads directory
$images = glob($directory);
// Randomise/shuffle the images
shuffle($images);
foreach( $images as $image ):
if ($image) { ?>
<figure class="unit_25">
<?php echo "<img src='" . $image . "'>"; ?>
</figure>
<? }
endforeach;
?>
</div>
我尝试创建两个单独的图像数组并使用 Shuffle 合并它们,但没有成功。
【问题讨论】:
标签: php