dtt78245 2014-06-05 21:52
浏览 100
已采纳

php唯一的rand()里面的数字

I am trying to put a load of images in a random order using php this is what I have tried

for ($i=47; $i < 54; $i++) {
            echo "<img width='205' src='IMG_03";
            echo rand(47,53);
            echo ".jpeg' alt=''>";  
}

But this code includes duplicates how could I do this without having the same random number between 47 and 53 twice?

  • 写回答

3条回答 默认 最新

  • douyimin1083 2014-06-05 21:58
    关注
    <?php
    
    $numbers = range(47, 54);
    shuffle($numbers);
    
    foreach($numbers as $n) {
        echo '<img src="IMG_03'.$n.'.jpg" alt="" />';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal
  • ¥15 VS2022创建MVC framework提示:预安装的程序包具有对缺少的注册表值的引用
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义
  • ¥15 嵌入式--定时器使用
  • ¥20 51单片机学习中的问题
  • ¥30 Windows Server 2016利用兩張網卡處理兩個不同網絡
  • ¥15 Python中knn问题
  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库