我希望帖子能够回应一个随机图像,例如,选择3张图像。
我希望它能回显img1或img2或img3。
这是我到目前为止所做的:
echo '<img src="http://example.com/wp-content/uploads/image-default.png" />' || echo '<img src="http://example.com/wp-content/uploads/image-default.png" />';
如何通过选择提供随机图片?
答案 0 :(得分:0)
array_rand
选择随机图片
$imageStack = [];
array_push($imageStack, '<img src="http://example.com/wp-content/uploads/image-default-1.png" />');
array_push($imageStack, '<img src="http://example.com/wp-content/uploads/image-default-2.png" />');
array_push($imageStack, '<img src="http://example.com/wp-content/uploads/image-default-3.png" />');
print_r($imageStack);
echo 'random';
$displayImage = array_rand($imageStack);
print_r($imageStack[$displayImage]);
&#13;