如何在PHP数组链接中添加随机数查询字符串

如何在PHP数组链接中添加随机数查询字符串,php,arrays,string,url,random,Php,Arrays,String,Url,Random,目标是在PHP数组中旋转图像的末尾添加一个随机数,以防止浏览器缓存图像。这个数字应该附加到图像URL的末尾,我有这个数组,它工作得很好。我有一个随机数发生器,它可以工作。当使用PHP将随机数应用于数组中的链接时,我犯了一些错误 以下是包含链接和图像的阵列示例: <?php $content1 = '<a href="http://example.net" title="Example 1" target="_blank"><img src="http://example.

目标是在PHP数组中旋转图像的末尾添加一个随机数,以防止浏览器缓存图像。这个数字应该附加到图像URL的末尾,我有这个数组,它工作得很好。我有一个随机数发生器,它可以工作。当使用PHP将随机数应用于数组中的链接时,我犯了一些错误

以下是包含链接和图像的阵列示例:

<?php
$content1 = '<a href="http://example.net" title="Example 1" target="_blank"><img src="http://example.com/gallery/image-1.png" alt="Image 1" width="300" height="250" class="gallery-image"></a>';
$content2 = '<a href="http://example.net" title="Example 2" target="_blank"><img src="http://example.com/gallery/image-2.png" alt="Image 2" width="300" height="250" class="gallery-image"></a>';
$content3 = '<a href="http://example.net" title="Example 3" target="_blank"><img src="http://example.com/gallery/image-3.png" alt="Image 3" width="300" height="250" class="gallery-image"></a>';
$content4 = '<a href="http://example.net" title="Example 4" target="_blank"><img src="http://example.com/gallery/image-3.png" alt="Image 4" width="300" height="250" class="gallery-image"></a>';
$content = array($content1, $content2, $content3, $content4,);
shuffle($content);
?>
<?php print $content[0] ?>

这是随机数生成器:

<?php echo rand() . "\n"; ?>

我想要的应该是这样的:

$content1 = '<a href="http://example.net" title="Example 1" target="_blank"><img src="http://example.com/gallery/image-1.png?29384756" alt="Image 1" width="300" height="250" class="gallery-image"></a>';
$content1='';
我曾尝试将随机数生成器放入数组的文本字符串中,但我做了一些错误的事情,因为要么它不会生成数字,要么PHP代码显示在HTML中,因此我不确定随机数将如何在数组HTML文本中生成

同样,目标是在图像URL的末尾添加一个随机数查询字符串,以便阵列仍然显示图像,并防止浏览器在刷新页面时缓存图像

有什么想法吗?有更好的方法吗?

一个简单的例子:

$rand = rand();
// ...
$content2 = '<a href="http://example.net" title="Example 2" target="_blank"><img src="http://example.com/gallery/image-2.png?' . $rand .'" alt="Image 2" width="300" height="250" class="gallery-image"></a>';
// ...
$content = array($content1, $content2, $content3, $content4,);
shuffle($content);
$rand=rand();
// ...
$content2='';
// ...
$content=array($content1,$content2,$content3,$content4,);
洗牌($内容);